Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get caffemodelpath argument from arguments #6

Merged
merged 2 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.caffemodel
.idea/
*.png
*.jpg
*.dump
*.pyc
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion bin/convert_image_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
Binary file removed neural_art/__init__.pyc
Binary file not shown.
Binary file removed neural_art/image_converters/__init__.pyc
Binary file not shown.
Binary file removed neural_art/image_converters/image_converter.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import chainer.functions
import neural_art
import numpy
import scipy.optimize
import image_converter
import openopt

Expand Down
Binary file not shown.
Binary file removed neural_art/models/__init__.pyc
Binary file not shown.
Binary file removed neural_art/models/vgg.pyc
Binary file not shown.
11 changes: 7 additions & 4 deletions neural_art/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file removed neural_art/utility.pyc
Binary file not shown.
Binary file removed neural_art/utility_old.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
numpy
openopt
cvxopt
chainer
pillow