new_contents: import os
  from keras.applications.vgg16 import VGG16
  from keras.preprocessing.image import ImageDataGenerator
  from keras.models import Sequential, Model
  from keras.layers import Input, Activation, Dropout, Flatten, Dense
  from keras.preprocessing.image import ImageDataGenerator
  from keras import optimizers
  import numpy as np
  from smallcnn import save_history
  
  
  classes = ['Tulip', 'Snowdrop', 'LilyValley', 'Bluebell', 'Crocus',
             'Iris', 'Tigerlily', 'Daffodil', 'Fritillary', 'Sunflower',
             'Daisy', 'ColtsFoot', 'Dandelion', 'Cowslip', 'Buttercup',
             'Windflower', 'Pansy']
  
  batch_size = 32
  nb_classes = len(classes)
  
  img_rows, img_cols = 150, 150
  channels = 3
  
  train_data_dir = 'train_images'
  validation_data_dir = 'test_images'
  
  nb_train_samples = 1190
  nb_val_samples = 170
  nb_epoch = 50
  
  result_dir = 'results'
  if not os.path.exists(result_dir):
      os.mkdir(result_dir)
  
  
  if __name__ == '__main__':
      # VGG16モデルで学習済み重みは使わずランダムにする
      # Fully-connected層（FC）はいらないのでinclude_top=False）
      input_tensor = Input(shape=(img_rows, img_cols, 3))
      vgg16 = VGG16(include_top=False, weights=None, input_tensor=input_tensor)
  
      # FC層を構築
      top_model = Sequential()
      top_model.add(Flatten(input_shape=vgg16.output_shape[1:]))
      top_model.add(Dense(256, activation='relu'))
      top_model.add(Dropout(0.5))
      top_model.add(Dense(nb_classes, activation='softmax'))
  
      # VGG16とFCを接続
      model = Model(input=vgg16.input, output=top_model(vgg16.output))
  
      # VGG16をスクラッチから学習
      model.compile(loss='categorical_crossentropy',
                    optimizer='adam',
                    metrics=['accuracy'])
  
      train_datagen = ImageDataGenerator(
          rescale=1.0 / 255,
          shear_range=0.2,
          zoom_range=0.2,
          horizontal_flip=True)
  
      test_datagen = ImageDataGenerator(rescale=1.0 / 255)
  
      train_generator = train_datagen.flow_from_directory(
          train_data_dir,
          target_size=(img_rows, img_cols),
          color_mode='rgb',
          classes=classes,
          class_mode='categorical',
          batch_size=batch_size,
          shuffle=True)
  
      validation_generator = test_datagen.flow_from_directory(
          validation_data_dir,
          target_size=(img_rows, img_cols),
          color_mode='rgb',
          classes=classes,
          class_mode='categorical',
          batch_size=batch_size,
          shuffle=True)
  
      # モデル訓練
      history = model.fit_generator(
          train_generator,
          samples_per_epoch=nb_train_samples,
          nb_epoch=nb_epoch,
          validation_data=validation_generator,
          nb_val_samples=nb_val_samples)
  
      model.save_weights(os.path.join(result_dir, 'vgg_scratch.h5'))
      save_history(history, os.path.join(result_dir, 'history_vgg_scratch.txt'))
  
subject: Add vgg_scratch.py