diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | data/base_dataset.py | 5 | ||||
| -rw-r--r-- | options/base_options.py | 1 | ||||
| -rw-r--r-- | options/test_options.py | 1 | ||||
| -rwxr-xr-x | run-flow.sh | 7 | ||||
| -rwxr-xr-x | run-gan.sh | 37 | ||||
| -rwxr-xr-x | run-messi.sh | 38 | ||||
| -rwxr-xr-x | run-wood.sh | 37 | ||||
| -rwxr-xr-x | run.sh | 4 | ||||
| -rwxr-xr-x | run100k.sh | 32 | ||||
| -rwxr-xr-x | test-all.sh | 24 | ||||
| -rw-r--r-- | test-datasets.sh | 26 | ||||
| -rw-r--r-- | test.py | 47 |
13 files changed, 237 insertions, 25 deletions
@@ -42,3 +42,6 @@ test/data/legacy_serialized.pt *~ .idea recursive/ +mov/ +*.swp + diff --git a/data/base_dataset.py b/data/base_dataset.py index 7cfac54..12fd0b2 100644 --- a/data/base_dataset.py +++ b/data/base_dataset.py @@ -19,7 +19,10 @@ def get_transform(opt): if opt.resize_or_crop == 'resize_and_crop': osize = [opt.loadSize, opt.loadSize] transform_list.append(transforms.Scale(osize, Image.BICUBIC)) - transform_list.append(transforms.RandomCrop(opt.fineSize)) + if opt.center_crop: + transform_list.append(transforms.CenterCrop(opt.fineSize)) + else: + transform_list.append(transforms.RandomCrop(opt.fineSize)) elif opt.resize_or_crop == 'crop': transform_list.append(transforms.RandomCrop(opt.fineSize)) elif opt.resize_or_crop == 'scale_width': diff --git a/options/base_options.py b/options/base_options.py index 150174b..d569928 100644 --- a/options/base_options.py +++ b/options/base_options.py @@ -41,6 +41,7 @@ class BaseOptions(): self.parser.add_argument('--resize_or_crop', type=str, default='resize_and_crop', help='scaling and cropping of images at load time [resize_and_crop|crop|scale_width|scale_width_and_crop]') self.parser.add_argument('--no_flip', action='store_true', help='if specified, do not flip the images for data augmentation') self.parser.add_argument('--init_type', type=str, default='normal', help='network initialization [normal|xavier|kaiming|orthogonal]') + self.parser.add_argument('--center_crop', action='store_true', help='center crop instead of random crop') self.initialized = True diff --git a/options/test_options.py b/options/test_options.py index f8c3a31..418d5e6 100644 --- a/options/test_options.py +++ b/options/test_options.py @@ -12,4 +12,5 @@ class TestOptions(BaseOptions): self.parser.add_argument('--phase', type=str, default='test', help='train, val, test, etc') self.parser.add_argument('--which_epoch', type=str, default='latest', help='which epoch to load? set to latest to use latest cached model') self.parser.add_argument('--how_many', type=int, default=50, help='how many test images to run') + self.parser.add_argument('--mov', type=str, help='filename of movie to export') self.isTrain = False diff --git a/run-flow.sh b/run-flow.sh index 7b7ac4f..3f650dc 100755 --- a/run-flow.sh +++ b/run-flow.sh @@ -1,4 +1,4 @@ -dataset="woodflow" +dataset="woodflowfixed" #/home/lens/Desktop/dataset-random.pl @@ -17,11 +17,10 @@ python train.py \ --which_direction AtoB \ --lambda_B 100 \ --dataset_mode aligned \ + --continue_train \ + --which_epoch latest \ --no_lsgan --norm batch --pool_size 0 -# --continue_train \ -# --which_epoch latest \ - #python canny-cv.py \ # --dataroot /home/ubuntu/Desktop/thumbs/wood/B/train/ \ # --name woodcanny \ diff --git a/run-gan.sh b/run-gan.sh new file mode 100755 index 0000000..310f7b5 --- /dev/null +++ b/run-gan.sh @@ -0,0 +1,37 @@ +dataset="woodscaled_unaligned" + +#/home/lens/Desktop/dataset-random.pl +# +#python datasets/combine_A_and_B.py \ +# --fold_A "/home/lens/Desktop/thumbs/$dataset/A" \ +# --fold_B "/home/lens/Desktop/thumbs/$dataset/B" \ +# --fold_AB "./datasets/$dataset/" + +python train.py \ + --dataroot "./datasets/$dataset" \ + --name "$dataset" \ + --model cycle_gan \ + --loadSize 256 \ + --fineSize 256 \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --lambda_B 100 \ + --dataset_mode aligned \ + --no_lsgan --norm batch --pool_size 0 \ + --continue_train + +python test.py \ + --dataroot "/home/lens/Desktop/thumbs/$dataset/A/train/" \ + --name "$dataset" \ + --start_img "/home/lens/Desktop/thumbs/$dataset/A/train/frame_1008.png" \ + --how_many 1000 \ + --model test \ + --aspect_ratio 1.777777 \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --dataset_mode recursive \ + --loadSize 256 \ + --fineSize 256 \ + --norm batch + + diff --git a/run-messi.sh b/run-messi.sh new file mode 100755 index 0000000..63d9a9a --- /dev/null +++ b/run-messi.sh @@ -0,0 +1,38 @@ +dataset="messi" + +#perl /home/lens/Desktop/pair-dataset.pl +#sleep 1 + +#python datasets/combine_A_and_B.py \ +# --fold_A "/home/lens/Desktop/thumbs/$dataset/A" \ +# --fold_B "/home/lens/Desktop/thumbs/$dataset/B" \ +# --fold_AB "./datasets/$dataset/" +#sleep 1 + +#python train.py \ +# --dataroot "./datasets/$dataset" \ +# --name "$dataset" \ +# --model pix2pix \ +# --loadSize 256 \ +# --fineSize 256 \ +# --which_model_netG unet_256 \ +# --which_direction AtoB \ +# --lambda_B 100 \ +# --dataset_mode aligned \ +# --no_lsgan --norm batch --pool_size 0 + +python test.py \ + --dataroot "/home/lens/Desktop/thumbs/$dataset/A/train/" \ + --name "$dataset" \ + --start_img "/home/lens/Desktop/thumbs/$dataset/A/train/frame_0000.png" \ + --how_many 500 \ + --model test \ + --aspect_ratio 1.777777 \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --dataset_mode recursive \ + --loadSize 286 \ + --fineSize 256 \ + --norm batch + #--center_crop \ + diff --git a/run-wood.sh b/run-wood.sh new file mode 100755 index 0000000..d053777 --- /dev/null +++ b/run-wood.sh @@ -0,0 +1,37 @@ +dataset="randomcrops5k" + +#/home/lens/Desktop/dataset-random.pl +# +#python datasets/combine_A_and_B.py \ +# --fold_A "/home/lens/Desktop/thumbs/$dataset/A" \ +# --fold_B "/home/lens/Desktop/thumbs/$dataset/B" \ +# --fold_AB "./datasets/$dataset/" +# python train.py \ +# --dataroot "./datasets/$dataset" \ +# --name "$dataset" \ +# --model pix2pix \ +# --loadSize 256 \ +# --fineSize 256 \ +# --which_model_netG unet_256 \ +# --which_direction AtoB \ +# --lambda_B 100 \ +# --dataset_mode aligned \ +# --no_lsgan --norm batch --pool_size 0 \ +# --continue_train + +python test.py \ + --dataroot "/home/lens/Desktop/thumbs/$dataset/A/train/" \ + --name "$dataset" \ + --start_img "/home/lens/Desktop/thumbs/$dataset/A/train/frame_0000.png" \ + --how_many 500 \ + --model test \ + --aspect_ratio 1.777777 \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --dataset_mode recursive \ + --loadSize 264 \ + --center_crop \ + --fineSize 256 \ + --norm batch + + @@ -31,8 +31,8 @@ python test.py \ --which_model_netG unet_256 \ --which_direction AtoB \ --dataset_mode recursive \ - --loadSize 256 \ - --fineSize 256 \ --norm batch +# --loadSize 256 \ +# --fineSize 256 \ diff --git a/run100k.sh b/run100k.sh new file mode 100755 index 0000000..1ad9e77 --- /dev/null +++ b/run100k.sh @@ -0,0 +1,32 @@ +dataset="randomcrops100k" + +/home/lens/Desktop/dataset-random.pl + +python datasets/combine_A_and_B.py \ + --fold_A "/home/lens/Desktop/thumbs/$dataset/A" \ + --fold_B "/home/lens/Desktop/thumbs/$dataset/B" \ + --fold_AB "./datasets/$dataset/" + +python train.py \ + --dataroot "./datasets/$dataset" \ + --name "$dataset" \ + --model pix2pix \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --lambda_B 100 \ + --dataset_mode aligned \ + --no_lsgan --norm batch --pool_size 0 + +python test.py \ + --dataroot "/home/lens/Desktop/thumbs/$dataset/A/train/" \ + --name "$dataset" \ + --start_img "/home/lens/Desktop/thumbs/$dataset/A/train/frame_0000.png" \ + --how_many 2000 \ + --model test \ + --aspect_ratio 1.777777 \ + --which_model_netG unet_256 \ + --which_direction AtoB \ + --dataset_mode recursive \ + --norm batch + + diff --git a/test-all.sh b/test-all.sh new file mode 100755 index 0000000..675966e --- /dev/null +++ b/test-all.sh @@ -0,0 +1,24 @@ +declare -a datasets=("/home/lens/Desktop/skull/") +declare -a checkpoints=("messi" "randomcrops100k" "randomcrops_30000_4" "randomcrops5k" "woodscaled" "woodscaled_4") + +for ds in "${datasets[@]}" +do + +bs=$(basename $ds) + +for i in "${checkpoints[@]}" +do + echo $ds + echo $i + + python test.py \ + --dataroot $ds \ + --name $i --mov "${bs}_warp_${i}" \ + --model test --dataset_mode single --experiment woodwarp \ + --which_model_netG unet_256 --which_direction AtoB \ + --loadSize 256 --fineSize 256 --norm batch --how_many 10000 + +done + +done + diff --git a/test-datasets.sh b/test-datasets.sh new file mode 100644 index 0000000..3629170 --- /dev/null +++ b/test-datasets.sh @@ -0,0 +1,26 @@ +declare -a datasets=("blended_wood_canny_leaves" "blended_wood_canny_typical" "blended_wood_canny_more_edges_poorly_trained") +declare -a checkpoints=("messi" "randomcrops100k" "randomcrops_30000_4" "randomcrops5k" "woodscaled" "woodscaled_4") + +basedir="/home/lens/code/torch-warp/" + +for ds in "${datasets[@]}" +do + +bs=$(basename $ds) + +for i in "${checkpoints[@]}" +do + echo $ds + echo $i + + python test.py \ + --dataroot "${basedir}${ds}/256/"\ + --name $i --mov "${bs}_warp_${i}" \ + --model test --dataset_mode single --experiment woodwarp \ + --which_model_netG unet_256 --which_direction AtoB \ + --loadSize 256 --fineSize 256 --norm batch --how_many 10000 + +done + +done + @@ -6,7 +6,7 @@ from util.visualizer import Visualizer from util.util import mkdirs from util import html from shutil import move, copyfile -from PIL import Image, ImageOps +from PIL import Image, ImageOps, ImageFilter from skimage.transform import resize from scipy.misc import imresize from shutil import copyfile, rmtree @@ -24,11 +24,13 @@ if __name__ == '__main__': opt.experiment = opt.start_img.split("/")[-1].split(".")[0] render_dir = opt.results_dir + opt.name + "/exp:" + opt.experiment + "/" + mov_dir = "mov/" if os.path.exists(render_dir): - rmtree(render_dir) + rmtree(render_dir) mkdirs(render_dir) - copyfile(opt.start_img, render_dir + "frame_00000.png") + if opt.start_img != 'test.jpg': + copyfile(opt.start_img, render_dir + "frame_00000.png") data_loader = CreateRecursiveDataLoader(opt) dataset = data_loader.load_data() @@ -49,11 +51,11 @@ if __name__ == '__main__': img_path = model.get_image_paths() print('%04d: process image... %s' % (i, img_path)) ims = visualizer.save_images(webpage, visuals, img_path, aspect_ratio=opt.aspect_ratio) + im = visuals['fake_B'] + save_path = render_dir + "frame_{:05d}_tmp.png".format(i+1) + final_path = render_dir + "frame_{:05d}.png".format(i+1) if dataset.name() == 'RecursiveDatasetDataLoader': # print(visuals.keys()) - im = visuals['fake_B'] - save_path = render_dir + "frame_{:05d}_tmp.png".format(i+1) - final_path = render_dir + "frame_{:05d}.png".format(i+1) # s = 256 # p = 8 # im = imresize(im, (s-p, s-p), interp='bicubic') @@ -67,29 +69,38 @@ if __name__ == '__main__': tmp_im = im.copy() array_a = np.multiply(im, frac_a) array_b = np.multiply(last_im, frac_b) - # im = np.add(array_a, array_b).astype('int8') - # print(im.shape, im.dtype) - last_im = np.roll(tmp_im, 1, axis=1) - else: + im = np.add(array_a, array_b).astype('int8') + #print(im.shape, im.dtype) + last_im = tmp_im # np.roll(tmp_im, 1, axis=1) + elif i < 2: last_im = im.copy() print(im.shape, im.dtype) - image_pil = Image.fromarray(im, mode='RGB') - image_pil.save(save_path) - os.rename(save_path, final_path) + image_pil = Image.fromarray(im, mode='RGB') + # image_pil.filter(ImageFilter.SHARPEN) + image_pil = image_pil.resize((456,256), Image.ANTIALIAS) + image_pil.save(save_path) + os.rename(save_path, final_path) webpage.save() - os.remove(render_dir + "frame_00000.png") + if os.path.exists(render_dir + "frame_00000.png"): + os.remove(render_dir + "frame_00000.png") - cmd = ("/usr/bin/ffmpeg", "-i", render_dir + "frame_%05d.png", "-y", "-c:v", "libx264", "-vf", "fps=30", "-pix_fmt", "yuv420p", render_dir + opt.name + "_" + opt.experiment + ".mp4") + if opt.mov is not None: + filename = opt.mov + if not filename.endswith('.mp4'): + filename += '.mp4' + else: + filename = opt.name + "_" + opt.experiment + ".mp4" + cmd = ("ffmpeg", "-i", render_dir + "frame_%05d.png", "-y", "-c:v", "libx264", "-vf", "fps=30", "-pix_fmt", "yuv420p", mov_dir + filename) process = subprocess.Popen(cmd, stdout=subprocess.PIPE) output, error = process.communicate() print("________") - print("\n") - cmd = ("scp", render_dir + opt.name + "_" + opt.experiment + ".mp4", "jules@asdf.us:asdf/neural/") + cmd = ("scp", mov_dir + filename, "jules@asdf.us:asdf/neural/") process = subprocess.Popen(cmd, stdout=subprocess.PIPE) output, error = process.communicate() + print("https://asdf.us/neural/" + filename) print("\n") - print("https://asdf.us/neural/" + opt.name + "_" + opt.experiment + ".mp4") + |
