def main(): seed = 42 np.random.seed(seed) current_dir = os.path.dirname(__file__) sys.path.append(os.path.join(current_dir, '..')) current_dir = current_dir if current_dir is not '' else '.' img_dir_path = 'jpg' txt_dir_path = 'flowers/text_c10' model_dir_path = current_dir + '/models' img_width = 32 img_height = 32 from dcgan import DCGan from image_utils import img_from_normalized_img from img_cap_loader import load_normalized_img_and_its_text image_label_pairs = load_normalized_img_and_its_text(img_dir_path, txt_dir_path, img_width=img_width, img_height=img_height) shuffle(image_label_pairs) gan = DCGan() gan.load_model(model_dir_path) for i in range(10): image_label_pair = image_label_pairs[i] normalized_image = image_label_pair[0] text = image_label_pair[1] print(text) image = img_from_normalized_img(normalized_image) image.save(current_dir + '/data/outputs/' + DCGan.model_name + '-generated-' + str(i) + '-0.png') for j in range(3): generated_image = gan.generate_image_from_text(text) generated_image.save(current_dir + '/data/outputs/' + DCGan.model_name + '-generated-' + str(i) + '-' + str(j) + '.png')
if mode == 'train': #training start_time = time.time() logs = gan.fit(model_dir_path=model_dir_path, image_label_pairs=image_label_pairs, snapshot_dir_path=current_dir + snapshots_dir_path, snapshot_interval=10, batch_size=batch_size, epochs=epochs) from training_plot import on_epoch_end on_epoch_end(logs) end_time = time.time() print(end_time - start_time) elif mode == 'test': #testing from dcgan import DCGan gan = DCGan() gan.load_model(model_dir_path) text = 'person holding black guitar' generated_image = gan.generate_image_from_text(text) generated_image.save(current_dir + output_dir_path + DCGan.model_name + '-generated-' + str(0) + '-' + str(0) + '.png') else: print('Wrong mode string')