def generate_single_svm_train(one_class_train_file): trainfile = one_class_train_file savepath = one_class_train_file.replace('txt', 'pkl') images = [] Y = [] if os.path.isfile(savepath): print("restoring svm dataset " + savepath) images, Y = prep.load_from_pkl(savepath) else: print("loading svm dataset " + savepath) images, Y = prep.load_train_proposals(trainfile, 2, threshold=0.3, svm=True, save=True, save_path=savepath) return images, Y
n_epoch=20, validation_set=0.1, shuffle=True, show_metric=True, batch_size=64, snapshot_step=200, snapshot_epoch=False, run_id='alexnet_rcnnflowers2' ) # epoch = 1000 Start training (apply gradient descent algorithm) # Save the model model.save('fine_tune_model_save.model') if __name__ == '__main__': if os.path.isfile('dataset.pkl'): print("Loading Data") X, Y = prep.load_from_pkl('dataset.pkl') else: print("Reading Data") X, Y = prep.load_train_proposals('refine_list.txt', 2, save=True) print("DONE") restore = False if os.path.isfile('fine_tune_model_save.model'): restore = True print("Continue training") net = create_alexnet(3, restore) fine_tune_Alexnet(net, X, Y)
print("Loading the fine tuned model") model.load('fine_tune_model_save.model') elif os.path.isfile('model_save.model'): print("Loading the alexnet") model.load('model_save.model') else: print("No file to load, error") return False model.fit(X, Y, n_epoch=10, validation_set=0.1, shuffle=True, show_metric=True, batch_size=64, snapshot_step=200, snapshot_epoch=False, run_id='alexnet_rcnnflowers2') # epoch = 1000 # Save the model model.save('fine_tune_model_save.model') if __name__ == '__main__': if os.path.isfile('dataset.pkl'): print("Loading Data") X, Y = prep.load_from_pkl('dataset.pkl') else: print("Reading Data") X, Y = prep.load_train_proposals('refine_list.txt', 2, save=True) print("DONE") restore = False if os.path.isfile('fine_tune_model_save.model'): restore = True print("Continue training") net = create_alexnet(3, restore) fine_tune_Alexnet(net,X,Y)
print("Loading the fine tuned model") model.load(SOURCE+'model/rcnn/'+'fine_tune_model_save.model') elif os.path.isfile(SOURCE+'model/rcnn/'+'model_save.model'): print("Loading the alexnet") model.load(SOURCE+'model/rcnn/'+'model_save.model') else: print("No file to load, error") return False model.fit(X, Y, n_epoch=10, validation_set=0.1, shuffle=True, show_metric=True, batch_size=64, snapshot_step=200, snapshot_epoch=False, run_id='alexnet_rcnnflowers2') # epoch = 1000 # Save the model model.save(SOURCE+'model/rcnn/'+'fine_tune_model_save.model') if __name__ == '__main__': if os.path.isfile(SOURCE+'model/rcnn/'+'dataset.pkl'): print("Loading Data") X, Y = prep.load_from_pkl(SOURCE+'model/rcnn/'+'dataset.pkl') else: print("Reading Data") X, Y = prep.load_train_proposals('refine_list.txt', 2, save=True) print("DONE") restore = False if os.path.isfile(SOURCE+'model/rcnn/'+'fine_tune_model_save.model'): restore = True print("Continue training") net = create_alexnet(3, restore) fine_tune_Alexnet(net,X,Y)