def main(args): exec_time = datetime.now().strftime('%Y%m%d-%H%M%S') tensorboard = TensorBoard(log_dir=f'log/vae/{exec_time}', update_freq='batch') new_model = args.new_model epochs = int(args.epochs) steps = int(args.steps) # instantiate VAE vae = VAE() if new_model else load_vae(WEIGHT_FILE_NAME) # get training set and validation set generators t_gen, v_gen = get_generators(INPUT_DIR_NAME, TV_RATIO) # start training! vae.train(t_gen, v_gen, epochs=epochs, steps_per_epoch=steps, validation_steps=int(steps * TV_RATIO), workers=10, callbacks=[tensorboard]) # save model weights vae.save_weights(WEIGHT_FILE_NAME)
def main(args): new_model = args.new_model N = int(args.N) epochs = int(args.epochs) vae = VAE() if not new_model: try: vae.set_weights('./vae/weights.h5') except: print("Either set --new_model or ensure ./vae/weights.h5 exists") raise try: data, N = import_data(N) except: print('NO DATA FOUND') raise print('DATA SHAPE = {}'.format(data.shape)) for epoch in range(epochs): print('EPOCH ' + str(epoch)) vae.train(data) vae.save_weights('./vae/weights.h5')
def main(args): new_model = args.new_model S = int(args.S) N = int(args.N) batch = int(args.batch) model_name = str(args.model_name) print(args.alpha) alpha = float(args.alpha) vae = VAE() if not new_model: try: vae.set_weights('./vae/' + model_name + '/' + model_name + '_weights.h5') except: print("Either set --new_model or ensure ./vae/weights.h5 exists") raise else: if os.path.isdir('./vae/' + model_name): print("A model with this name already exists") else: os.mkdir('./vae/' + model_name) os.mkdir('./vae/' + model_name + '/log/') filelist = os.listdir(DIR_NAME) filelist = [x for x in filelist if x != '.DS_Store' and x != '.gitignore'] filelist.sort() for i in range(round(float(N - S) / batch)): data = import_data(S + i * batch, S + (i + 1) * batch, filelist) dataS = [] dataB = [] for d in data: beta = alpha + np.random.rand() * (1 - alpha) dataS.append( cv2.resize(crop(d, alpha * beta), dsize=(SCREEN_SIZE_X, SCREEN_SIZE_Y), interpolation=cv2.INTER_CUBIC)) dataB.append( cv2.resize(crop(d, beta), dsize=(SCREEN_SIZE_X, SCREEN_SIZE_Y), interpolation=cv2.INTER_CUBIC)) dataS = np.asarray(dataS) dataB = np.asarray(dataB) vae.train(dataS, dataB, model_name ) # uncomment this to train augmenting VAE, simple RNN (2) #vae.train(np.vstack([dataS, dataB]), np.vstack([dataS, dataB]), model_name) # uncomment this to train simple VAE, RNN (1) vae.save_weights('./vae/' + model_name + '/' + model_name + '_weights.h5') print('Imported {} / {}'.format(S + (i + 1) * batch, N))
def main(args): new_model = args.new_model S = int(args.S) N = int(args.N) batch = int(args.batch) epochs = int(args.epochs) model_name = str(args.model_name) vae = VAE() if not new_model: try: vae.set_weights('./vae/' + model_name + '_weights.h5') except: print("Either set --new_model or ensure ./vae/" + model_name + "_weights.h5 exists") raise elif not os.path.isdir('./vae/' + model_name): os.mkdir('./vae/' + model_name) os.mkdir('./vae/' + model_name + '/log/') filelist = os.listdir(DIR_NAME + model_name) filelist = [x for x in filelist if x != '.DS_Store' and x != '.gitignore'] filelist.sort() N = max(N, len(filelist)) for i in range(int(round(float(N - S) / batch) + 1)): dataS, dataB = import_data(S + i * batch, S + (i + 1) * batch, filelist, model_name) for epoch in range(epochs): vae.train( dataS, dataB, model_name ) # uncomment this to train augmenting VAE, simple RNN (2) #vae.train(np.vstack([dataS, dataB]), np.vstack([dataS, dataB]), model_name) # uncomment this to train simple VAE, RNN (1) vae.save_weights('./vae/' + model_name + '/' + model_name + '_weights.h5') print('Imported {} / {}'.format(S + (i + 1) * batch, N))