def save_bottleneck_features(X_train, X_val): # build original VGG16 model model = get_vgg_model.build_vgg_model(img_cols, img_rows, weights_path) print('Doing prediction on default VGG weights...') bottleneck_features_train = model.predict(X_train, batch_size=128, verbose=0) print('Prediction for train samples completed. Saving to disk...') np.save(open(w_path + train_feat_name, 'wb'), bottleneck_features_train) bottleneck_features_validation = model.predict(X_val, batch_size=128, verbose=0) print('Prediction for validation samples completed. Saving to disk...') np.save(open(w_path + val_feat_name, 'wb'), bottleneck_features_validation) print('Bottleneck features are saved at %s' % dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
img_rows, img_cols = he_load_data.IM_ROWS, he_load_data.IM_COLS # The HumanEva images are RGB. img_channels = 3 print('Loading training data...') if data_augmentation: X_train, Y_train, X_val, Y_val = he_load_data.load_aug_data() else: X_train, Y_train, X_val, Y_val = he_load_data.load_data() print(X_train.shape[0], 'train samples') print(X_val.shape[0], 'test samples') # BUILD THE VGG MODEL ================== print('building vgg model...') model = get_vgg_model.build_vgg_model(img_cols, img_rows, weights_path) # BUILD THE TOPMODEL (upon the VGG16 model) =========================== print('building the top model...') top_model = get_he_topmodel.build_he_topmodel(model.output_shape[1:], fcLayers=topModConf, reg_w=REG_W_FC, reg_b=REG_B_FC, bn_eps=BN_EPS, dropout=DROPOUT_FC) # note that it is necessary to start with a fully-trained # classifier, including the top classifier, # in order to successfully do fine-tuning top_model.load_weights( top_model_weights_path
chk_path = '/home/edogan/checkpoints/' chk_file = chk_path + 'finetune_umpm_16_20170221-1133/weights-improvement-022-129.35.hdf5' prd_path = '/home/edogan/predictions/' prd_file = prd_path + 'finetune_umpm_16.npy' prd_file_val = prd_path + 'finetune_umpm_16_val.npy' topModConf = [1024] batch_size = 128 nb_parts = umpm_load_data.NUM_PARTS # input image dimensions img_rows, img_cols = umpm_load_data.IM_ROWS, umpm_load_data.IM_COLS img_channels = 3 model = get_vgg_model.build_vgg_model(img_cols, img_rows) print('Building the top model...') top_model = get_umpm_topmodel.build_umpm_topmodel(model.output_shape[1:], fcLayers=topModConf) model.add(top_model) model.summary() # model.load_weights(chk_file) # print('Weights loaded: %s' % chk_file) # model.compile(loss='mse', # optimizer=SGD, # metrics=['mean_squared_error'])