示例#1
0
        width_shift_range=0.1,
        height_shift_range=0.1,
        zoom_range=0.1,
        horizontal_flip=True)
    datagen.fit(train_x)

    #valid_x, valid_y = load_data('valid', 'train')

    #model = load_model('model')
    #model.save_weights('weight')
    model = build_model()
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    #model.load_weights('best_w')
    history = History()
    model.fit_generator(
        datagen.flow(train_x, train_y, batch_size=128),
        steps_per_epoch=len(train_x) / 128 * 8,
        #steps_per_epoch = 1,
        epochs=50,
        #validation_data = (valid_x, valid_y),
        callbacks=[history])
    history.save('history')

    model.save(model_path)
    #model.save_weights('weight')
    #print('\nvalid:', model.evaluate(valid_x, valid_y)[1])

    exit()
示例#2
0
    history1 = History()

    model = build_model()
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    model.fit_generator(
        datagen.flow(data1_x, data1_y, batch_size=128),
        steps_per_epoch=len(data1_x) / 128 * 4,
        #steps_per_epoch = 1,
        epochs=50,
        validation_data=(valid_x, valid_y),
        callbacks=[history1])
    #model.fit(data1_x, data1_y, batch_size = 128, epochs = 100, validation_data = (valid_x, valid_y), callbacks = [history1])
    model.save('self_model')
    history1.save('history1')

    datagen.fit(data2_x)

    history2 = History()

    data2_y = to_categorical(model.predict_classes(data2_x, batch_size=128), 7)
    model2 = build_model()
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    model.fit_generator(
        datagen.flow(data2_x, data2_y, batch_size=128),
        steps_per_epoch=len(data2_x) / 128 * 4,
        #steps_per_epoch = 1,
        epochs=50,
示例#3
0
			rotation_range = 3,
			width_shift_range = 0.1,
			height_shift_range = 0.1,
			zoom_range = 0.1,
			horizontal_flip = True)
	datagen.fit(train_x)

	valid_x, valid_y = load_data('valid', 'train')


	#model = load_model('model')
	#model.save_weights('weight')
	model = build_dnn_model()
	model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
	#model.load_weights('best_w')
	history = History()
	model.fit_generator(
			datagen.flow(train_x, train_y, batch_size = 128),
			steps_per_epoch = len(train_x) / 128 * 2,
			#steps_per_epoch = 1,
			epochs = 50,
			validation_data = (valid_x, valid_y),
			callbacks = [history])
	history.save('dnn_history')

	#model.save(model_path)
	#model.save_weights('weight')
	print('\nvalid:', model.evaluate(valid_x, valid_y)[1])

	exit()