jrosebr1 / bat-country

A lightweight, extendible, easy to use Python package for deep dreaming and image generation with Caffe and CNNs.
MIT License
246 stars 62 forks source link

Changing the model from GoogLenet #2

Closed ayakubovich closed 9 years ago

ayakubovich commented 9 years ago

I'm getting some errors when I try to change the model from the default GoogLenet. I'm probably just not understanding the API correctly.

This works:

>>> BatCountry('/caffe-master/models/bvlc_googlenet')

But this doesn't:

>>> BatCountry('/caffe-master/models/bvlc_alexnet')  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "batcountry/batcountry.py", line 34, in __init__
    channel_swap=channels)
  File "/caffe-master/distribute/python/caffe/classifier.py", line 26, in __init__
    caffe.Net.__init__(self, model_file, pretrained_file, caffe.TEST)
RuntimeError: Could not open file /caffe-master/models/bvlc_alexnet/bvlc_googlenet.caffemodel

Are there additional arguments that need to be set when changing the model? I couldn't figure this out from the doc. In demo_bulk.py it seems like the only argument we pass is the path to the model.

jrosebr1 commented 9 years ago

@ayakubovich Sorry it's taken me so long to reply to this, definitely my fault. Take a look at the __init__ method of BatCountry, specifically the base_path, which is the path to your Caffe model directory, deploy_path which is the .prototxt file, and model_path which is your .caffemodel file. These variables come with initial values that enable GoogLeNet to be used out of the box, but can be overridden to handle other models.

amsimoes commented 9 years ago

I'm curious about this same way to change the model... I understand the python code but in pratice I don't know how to change it other than renaming my caffemodel's name to the default google one and the same for the prototxt file... although the base_path can be changed due to your "visualize_layers.py" code requesting it on the "--base-model" parameter... Isn't it possible to optionally request the user in CLI the parameter to some specific coffemodel and prototxt files, and if nothing gets written then assume it's the googleNet the user wants to work with... I'm going to research some way of doing this even with my python being very rusty nowadays :)

jrosebr1 commented 9 years ago

Asking for a user to manually specify a path via command line argument isn't very Python, so I wouldn't recommend doing that. Here is some example code to specify the paths to the base_path, model_path, and deploy_path using the BatCountry constructor:

bc = BatCountry(base_path="/path/to/directory/containing/prototxt_and_caffemodel', deploy_path='filename_of.prototxt', model_path='filename_of.caffemodel')

As long as you specify those parameters, everything should workj ust fine.

jrosebr1 commented 9 years ago

Going ahead and marking this issue as resolved.