def __init__(self): goods_dataset = GoodsDataset("dataset-181018.list", "dataset-181018.labels", settings.IMAGE_SIZE, settings.train_batch, settings.valid_batch, settings.multiply, settings.valid_percentage) train_set = goods_dataset.get_train_dataset() valid_set = goods_dataset.get_valid_dataset() input_tensor = keras.layers.Input(shape=(IMAGE_SIZE[0], IMAGE_SIZE[1], 3)) base_model = InceptionV3(weights='imagenet', include_top=False, pooling='avg', input_tensor=input_tensor) output_layer_number = 248 intermediate_layer_model = keras.Model( inputs=base_model.input, outputs=base_model.layers[output_layer_number].output) def _intermediate_processing(images, labels): images = intermediate_layer_model.predict(images, steps=77) return images, labels self.train_set = train_set.map( _intermediate_processing) #, num_parallel_calls=8) self.valid_set = valid_set.map( _intermediate_processing) #, num_parallel_calls=8)
keras.callbacks.ModelCheckpoint( "./checkpoints/FINE_TUNE_MODEL_4_DIRECT_inceptionv3-181018-{epoch:02d}-{acc:.3f}-{val_acc:.3f}[{val_top_6:.3f}].hdf5", save_best_only=True, monitor='val_top_6', mode='max'), keras.callbacks.TensorBoard( log_dir='./tensorboard-incv4', write_images=True, ) ] goods_dataset = GoodsDataset("dataset-181018.list", "dataset-181018.labels", settings.IMAGE_SIZE, settings.train_batch, settings.valid_batch, settings.multiply, settings.valid_percentage) train_dataset = goods_dataset.get_train_dataset() valid_dataset = goods_dataset.get_valid_dataset() results = model.evaluate( goods_dataset.get_images_for_label(94).batch(16).repeat(), steps=6) print(results) model.fit( train_dataset.prefetch(2).repeat(), callbacks=callbacks, epochs=30, steps_per_epoch=1157, validation_data=valid_dataset.repeat(), validation_steps=77, ) """