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

load a caffe pre-trained model? #49

Closed
mnmoustafa opened this issue Apr 7, 2015 · 23 comments
Closed

load a caffe pre-trained model? #49

mnmoustafa opened this issue Apr 7, 2015 · 23 comments

Comments

@mnmoustafa
Copy link

It is not an issue per se.
Is it possible to load a pre-trained model from caffe (still nvidia branch) command line? For instance, if I want to start from the imagenet model (and weights) and modify/train the last layer, etc... or load something from the zoo.
Thanks,

@lukeyeager
Copy link
Member

It is possible, but it's not well documented. On the "New Image Classification Model" page, under the "Custom Network" tab, you have two form fields:

  1. Custom network - this is where you paste in the text of the train_val prototxt that you want to use.
  2. Pretrained model - if you know what you're doing, you can enter the path to a pretrained model here that corresponds to the network that you've entered above. It's not a file upload, you have to actually input the path to the file on the local filesystem.

@mnmoustafa
Copy link
Author

I see. Thank you. But how about loading a prebuilt data db?
On the "new image classification model" page, I see that it accepts only the actual jpg images.
My use case is as follows: I started from the CIFAR10 dataset (which is distributed as binaries not jpg images) and trained a network using caffe command-line. Can I continue fine tuning and testing individual images on this network with DIGITS?
Thanks,

@lukeyeager
Copy link
Member

You can definitely import your pretrained model and fine-tune it in DIGITS on other images. If you want to use the CIFAR10 dataset again, you'll have to extract the images from the distributed binary format into a folder of folders of images, like DIGITS expects, and create a dataset in DIGITS.

@mnmoustafa
Copy link
Author

Fair enough. Thank you lukeyeager for the prompt response. I appreciate if you consider adding an option in the future to import prebuilt leveldb data for instance.
Thanks,

@lukeyeager
Copy link
Member

consider adding an option in the future to import prebuilt data

Will do, thanks for the suggestion!

@kajwes
Copy link

kajwes commented May 6, 2015

Hi, I've got an additional question on this topic. I would like to create a model using custom network + pretrained model, but without having to specify a dataset. Since the model is already pretrained, I would like to be able to run the "Classify one image" or "classify many images" without having to train the network again.
Is this possible, or is there a simple way to create a "dummy dataset" which will work for let's say the ImageNet pretrained model?

@lukeyeager
Copy link
Member

I would like to be able to run the "Classify one image" or "classify many images" without having to train the network again.

DIGITS is not a deployment solution, it is a training system. As such, it has been designed assuming that datasets are created and models are trained within DIGITS. Also, the emphasis has been on making training efficient, not inference.

That being said, if you want to still use DIGITS to test a model, you can hack it together.

  • Save some image to /home/username/image.jpg or wherever.
  • Create a textfile train.txt using the same image once for each category 0-999:
/home/username/image.jpg 0
/home/username/image.jpg 1
/home/username/image.jpg 2
...
/home/username/image.jpg 999
  • Get synset_words.txt using this script
  • Go to New Image Classification Dataset > Upload Text Files.
    • Training set - train.txt as above
    • Validation set - none
    • Labels - synset_words.txt

Now, you have your "dummy dataset". Then, to create your model:

  • Go to New Image Classification Model
  • Select the dummy dataset
  • Set Training Epochs to 1 and Base Learning Rate to 0 (enabled in 42555f0)
  • Click on Standard Networks > AlexNet, then click on Customize
  • Under Pretrained model, enter the path to your imagenet pretrained model like "/home/username/bvlc_alexnet.caffemodel`

@kajwes
Copy link

kajwes commented May 7, 2015

Thanks. This worked out really well!
I see your point, that Digits primary goal is training models...

@ToruHironaka
Copy link

@lukeyeager I followed your comments on May 6 and my custom image dataset have been working just fine. However, I would like to make sure a thing about synset_word.txt (Labels). My own data path is like this. Is my synset_word.txt correct?

train.txt
/data/image/path/n100000/image01 0
/data/image/path/n100000/image02 0
.....
/data/image/path/n100001/image01 1
/data/image/path/n100001/image02 1
.....
/data/image/path/n100100/image01 100

val.txt
same style as the train.txt

my own synset_word.txt for my train.txt and val.txt
n100000 cat, lion, tiger 0
n100001 dog, wold, coyote 1
....
n100100 Elephant, 100

I followed synset_word.txt from ilsvrc12, is below.

n01440764 tench, Tinca tinca
n01443537 goldfish, Carassius auratus
n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias
n01491361 tiger shark, Galeocerdo cuvieri

In caffe, I do not have to set synset_word.txt unless you are going to classify images with classify command with synset_word.txt. However, DIGITS required label file. Why does DIGITS require Label file?

@lukeyeager
Copy link
Member

Is my synset_word.txt correct?

That should work fine. Is it not working for you?

Why does DIGITS require Label file?

For classification models, you need some sort of mapping from number to string. The network only outputs numbers and probabilities like:

0 - 0.001
1 - 0.355
2 - 0.100
...

With a labels.txt, I can convert this into:

0.1%  - "n01440764 tench, Tinca tinca"
35.5% - "n01443537 goldfish, Carassius auratus"
10%   - "n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias"
...

@ToruHironaka
Copy link

@lukeyeager Yes, my dataset works fine. I just wanna make sure about it. I am pretty much sure about that the label file is used for only classifying image files by applying a trained caffe model like AlexNet because caffe FT or Training do not require me the label file while I am creating my dataset. I can create it later. Am I correct? Therefore, I thought the label file was not necessary for DIGITS to creating dataset. However, DIGITS required me to upload the label file before I created my datasets. It is a good habit for me to create the label file before creating dataset.

@lukeyeager
Copy link
Member

It is a good habit for me to create the label file before creating dataset.

Yes. DIGITS wants all the information about your dataset all at once - you can't edit it after the fact. I'm contemplating ways to make that more flexible. Would it really be a big help to you to be able to add the labels file after the fact?

@krishhtof
Copy link

Hello @lukeyeager I have just started working with digits 2.0 and I am not being able to train the model using AlexNet for the CIFAR10 data set. it gives me the following error and training gets aborted:

ERROR: error code -8

relu4 -> conv4 (in-place)
Setting up relu4
Top shape: 100 384 1 1 (38400)
Creating layer conv5
Creating Layer conv5
conv5 <- conv4
conv5 -> conv5
Setting up conv5
Top shape: 100 256 1 1 (25600)
Creating layer relu5
Creating Layer relu5
relu5 <- conv5
relu5 -> conv5 (in-place)
Setting up relu5
Top shape: 100 256 1 1 (25600)
Creating layer pool5
Creating Layer pool5
pool5 <- conv5
pool5 -> pool5
Setting up pool5

Kindly help..Thanks

@lukeyeager
Copy link
Member

@krishhtof look at the "Raw caffe output" to see if you get more information.

If you still need help, please open a new issue rather than adding to this unrelated discussion.

@krishhtof
Copy link

Thank you, yes I have also joined another Group at G+ for Digits and put my query there too..

@alexkarargyris
Copy link

@lukeyeager I am trying to load the VGG 19-layer model from here on DIGITS 2. When I try to start the training it gives me the following error:

``
Initialized at 01:47:49 PM (1 second)
Error at 01:47:51 PM
(Total - 1 second)
ERROR: must specify a loss layer

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/digits/scheduler.py", line 455, in run_task
task.run(resources)
File "/usr/lib/python2.7/dist-packages/digits/task.py", line 177, in run
self.before_run()
File "/usr/lib/python2.7/dist-packages/digits/model/tasks/caffe_train.py", line 104, in before_run
self.save_prototxt_files()
File "/usr/lib/python2.7/dist-packages/digits/model/tasks/caffe_train.py", line 164, in save_prototxt_files
assert len(loss_layers) > 0, 'must specify a loss layer'
AssertionError: must specify a loss layer
``

What am I missing here? I tried to add a loss layer at the end but the same error. I am wondering if you can load it on your DIGITS. Thanks!

@JVR32
Copy link

JVR32 commented Jun 16, 2016

Hello,
I want to train a network, using a pretrained network for the weights.
In the field "Pretrained model(s)" of the tab "New Image Classification Model", I add the path to my model

D:\TEST_DIGITS\models\mymodel.caffemodel

I start training, but it stops because of an error : "file not found"
Check failed: fd != -1 (-1 vs. -1) File not found: C:/Programs/DIGITS-master/digits/jobs/20160616-102944-90e2/D

When I look at the command line that it generates during training, I see that the weight file was not composed as it should :
--weights=C:/Programs/DIGITS-master/digits/jobs/20160616-102944-90e2/D,/TEST_DIGITS/models/mymodel.caffemodel

So, for some reason, the path that I provided was not used, but the 'job path' was added as a prefix, and my model path was splitted.

So, the weight parameter should be as follows :
--weights=D:/TEST_DIGITS/models/mymodel.caffemodel

How can I make this work, anyone an idea?

@gheinrich
Copy link
Contributor

Oh, that's unfortunate, DIGITS is confusing the colon in D:\TEST_DIGITS with the separator we use in the presence of multiple pre-trained models. As a quick workaround you might want to change the separator on that line e.g.

args.append('--weights=%s' % ','.join(map(lambda x: self.path(x), self.pretrained_model.split('|'))))

@JVR32
Copy link

JVR32 commented Jun 16, 2016

Thanks.

Changed it in : args.append('--weights=%s' % self.pretrained_model)

That seems to work ...

@Dexter123193
Copy link

Dexter123193 commented May 13, 2018

Hi. I am uploading a pretrained network on DIGITS .
image

And I am getting this error
image

Can I get some help on this

@sanketfirodiya
Copy link

@Dexter123193 did you find a solution to this?

@Dexter123193
Copy link

Dexter123193 commented Jun 26, 2018 via email

@hanxinle
Copy link

@Dexter123193 Hi,When I upload the Pretrained Models on Digits 5.0.0 (installed by deb file). I got the same error page says "BadRequestKeyError ...". I am not quite clear about what you did. Can you tell me what files and where you put them?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests