diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13471e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.caffemodel +.idea/ +*.png +*.jpg +*.dump +*.pyc \ No newline at end of file diff --git a/README.md b/README.md index 73bd9a2..50a9fc0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,13 @@ neural_style_synthesizer INSTALL --------------- +The model files of neural networks are not contained in this repository. +You can get them from [nin_imagenet.caffemodel](https://gist.github.com/mavenlin/d802a5849de39225bcc6) and [VGG_ILSVRC_16_layers.caffemodel](https://gist.github.com/ksimonyan/211839e770f7b538e2d8#file-readme-md). + +Dependent libraries are installed with the following script. + ``` +pip install numpy pip install -r requirements.txt ``` @@ -19,6 +25,7 @@ with CPU ``` python bin/convert_image_multi.py \ + --modelpath=./VGG_ILSVRC_16_layers.caffemodel \ --iteration=100 \ --gpu=-1 \ --xsplit=1 --ysplit=1 --resize=300 \ @@ -31,6 +38,7 @@ with GPU ``` python bin/convert_image_multi.py \ + --modelpath=./VGG_ILSVRC_16_layers.caffemodel \ --iteration=100 \ --gpu=0 \ --xsplit=1 --ysplit=1 --resize=300 \ @@ -46,6 +54,7 @@ Split style image to 2x2 ``` python bin/convert_image_multi.py \ + --modelpath=./VGG_ILSVRC_16_layers.caffemodel \ --iteration=100 \ --gpu=0 \ --xsplit=2 --ysplit=2 --resize=300 \ diff --git a/bin/convert_image_multi.py b/bin/convert_image_multi.py index 7dd2864..d35df35 100644 --- a/bin/convert_image_multi.py +++ b/bin/convert_image_multi.py @@ -22,6 +22,7 @@ parser.add_argument("--debug_span", type=int, default=100) parser.add_argument("--average_pooling", action="store_true") parser.add_argument("--model", default="vgg") +parser.add_argument("--modelpath") parser.add_argument("--random_init", action="store_true") parser.add_argument("--init_image", default=None) args = parser.parse_args() @@ -44,7 +45,7 @@ init_img = neural_art.utility.load_image(args.init_image) init_img = neural_art.utility.resize_img(init_img, args.resize) -model = neural_art.utility.load_nn(args.model) +model = neural_art.utility.load_nn(args.model, modelpath=args.modelpath) converter = neural_art.image_converters.MultiReferenceImageConverter(texture_imgs, gpu=args.gpu, content_weight=args.content_weight, texture_weight=1, model=model, average_pooling=args.average_pooling) if args.debug: diff --git a/neural_art/__init__.pyc b/neural_art/__init__.pyc deleted file mode 100644 index a724036..0000000 Binary files a/neural_art/__init__.pyc and /dev/null differ diff --git a/neural_art/image_converters/__init__.pyc b/neural_art/image_converters/__init__.pyc deleted file mode 100644 index 3d6634a..0000000 Binary files a/neural_art/image_converters/__init__.pyc and /dev/null differ diff --git a/neural_art/image_converters/image_converter.pyc b/neural_art/image_converters/image_converter.pyc deleted file mode 100644 index 2dc6720..0000000 Binary files a/neural_art/image_converters/image_converter.pyc and /dev/null differ diff --git a/neural_art/image_converters/multi_reference_image_converter.py b/neural_art/image_converters/multi_reference_image_converter.py index 809bdad..81a5c18 100644 --- a/neural_art/image_converters/multi_reference_image_converter.py +++ b/neural_art/image_converters/multi_reference_image_converter.py @@ -5,7 +5,6 @@ import chainer.functions import neural_art import numpy -import scipy.optimize import image_converter import openopt diff --git a/neural_art/image_converters/multi_reference_image_converter.pyc b/neural_art/image_converters/multi_reference_image_converter.pyc deleted file mode 100644 index aa1486a..0000000 Binary files a/neural_art/image_converters/multi_reference_image_converter.pyc and /dev/null differ diff --git a/neural_art/models/__init__.pyc b/neural_art/models/__init__.pyc deleted file mode 100644 index 82c1af3..0000000 Binary files a/neural_art/models/__init__.pyc and /dev/null differ diff --git a/neural_art/models/vgg.pyc b/neural_art/models/vgg.pyc deleted file mode 100644 index 2d0c091..0000000 Binary files a/neural_art/models/vgg.pyc and /dev/null differ diff --git a/neural_art/utility.py b/neural_art/utility.py index b562a64..6a14cc7 100644 --- a/neural_art/utility.py +++ b/neural_art/utility.py @@ -29,17 +29,20 @@ def resize_img(img, max_length): new_h = max_length*orig_h/orig_w return img.resize((new_w,new_h)) -def load_nn(modelname): +def load_nn(modelname, modelpath = None): cachepath = "{}.dump".format(modelname) if os.path.exists(cachepath): nn = pickle.load(open(cachepath)) else: if modelname == 'vgg': - nn = neural_art.models.VGG("VGG_ILSVRC_16_layers.caffemodel", no_padding=False) + if modelpath is None: modelpath = "VGG_ILSVRC_16_layers.caffemodel" + nn = neural_art.models.VGG(modelpath, no_padding=False) elif modelname == 'vgg_nopad': - nn = neural_art.models.VGG("VGG_ILSVRC_16_layers.caffemodel", no_padding=True) + if modelpath is None: modelpath = "VGG_ILSVRC_16_layers.caffemodel" + nn = neural_art.models.VGG(modelpath, no_padding=True) elif modelname == 'nin': - nn = neural_art.models.NIN("nin_imagenet.caffemodel") + if modelpath is None: modelpath = "nin_imagenet.caffemodel" + nn = neural_art.models.NIN(modelpath) else: print 'invalid model name.' exit(1) diff --git a/neural_art/utility.pyc b/neural_art/utility.pyc deleted file mode 100644 index 96dfec5..0000000 Binary files a/neural_art/utility.pyc and /dev/null differ diff --git a/neural_art/utility_old.pyc b/neural_art/utility_old.pyc deleted file mode 100644 index bd6a2e1..0000000 Binary files a/neural_art/utility_old.pyc and /dev/null differ diff --git a/requirements.txt b/requirements.txt index 2af8018..ed4310d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ +numpy openopt cvxopt +chainer +pillow