コード例 #1
0
nb_classes = 9

# Load extracted bottleneck features
train_data = np.load(learning_data_root+'inceptionv3_bottleneck_features_train.npy')
validation_data = np.load(learning_data_root+'inceptionv3_bottleneck_features_validation.npy')
train_labels = np.load(learning_data_root+'inceptionv3_bottleneck_labels_training.npy')
validation_labels = np.load(learning_data_root+'inceptionv3_bottleneck_labels_validation.npy')


# Hyperparameters
learning_rates = [0.005, 0.001, 0.0005, 0.0001]

# Hyperparameter search
for lr in learning_rates:

    save_string = utility.save_string(0, lr)
    utility.log(save_string)

    # Create Optimizer
    optimizerSGD = tf.keras.optimizers.SGD(lr=lr, momentum=0.9)
    optimizerAdam = tf.keras.optimizers.Adam(lr=lr, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0,)

    model = TopClassifier().create_model(nb_classes=nb_classes, optimizer=optimizerAdam,input_shape=train_data.shape[1:])


    tbCallBack = tf.keras.callbacks.TensorBoard(log_dir='./logs', histogram_freq=0, batch_size=batch_size, write_graph=True,
                                    write_grads=False, write_images=False,
                                    #embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None
                                        )
    model.fit(train_data, train_labels,  
          epochs=epoch_size,  
コード例 #2
0
ファイル: train_vgg16.py プロジェクト: rahulsingh50/DL4CV-1
    validation_photo_to_label_dict,
    batch_size=batch_size,
    target_size=(img_width, img_height),
    train_or_valid='validation')

validation_generator = validation_multilabel_datagen.flow()

# Hyperparameters
num_freezed_layers_array = [19]
learning_rates = [0.001]

# Hyperparameter search
for num_freezed_layers in num_freezed_layers_array:
    for lr in learning_rates:

        save_string = utility.save_string(num_freezed_layers, lr)
        utility.log(save_string)

        # Create Optimizer
        optimizerSGD = tf.keras.optimizers.SGD(lr=lr, momentum=0.9)
        optimizerAdam = tf.keras.optimizers.Adam(
            lr=lr,
            beta_1=0.9,
            beta_2=0.999,
            epsilon=1e-08,
            decay=0.0,
        )

        # Create model
        model = VGG16Model().create_model(num_freezedLayers=num_freezed_layers,
                                          nb_classes=nb_classes,