コード例 #1
0
    "Coat","Sandal","Shirt","Sneaker","Bag","Ankle boot"]

# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)

num_classes = y_train.shape[1]
 
model = InceptionV3(weights='imagenet', include_top=False) #include_top=False excludes final FC layer

x = model.output
x = GlobalAveragePooling2D()(x)
x = Dense(config.fc_size, activation='relu')(x) #new FC layer, random init
predictions = Dense(len(labels), activation='softmax')(x) #new softmax layer
model = Model(inputs=model.input, outputs=predictions)
model._is_graph_network = False

NB_IV3_LAYERS_TO_FREEZE = 172

for layer in model.layers[:NB_IV3_LAYERS_TO_FREEZE]:
    layer.trainable = False
for layer in model.layers[NB_IV3_LAYERS_TO_FREEZE:]:
    layer.trainable = True
model.compile(optimizer=SGD(lr=0.001, momentum=0.9), loss='categorical_crossentropy', metrics=['accuracy'])

datagen = ImageDataGenerator(
    featurewise_center=True,
    featurewise_std_normalization=True,
    rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,