{
  "id": 12765,
  "title": "CNN + Caffe",
  "url": "/competitions/datasciencebowl/discussion/12765",
  "author_name": "",
  "post_date": "2015-03-10T21:46:50.277Z",
  "votes": null,
  "comment_count": 12,
  "views": 6952,
  "content": "<p>Hi&nbsp;</p>\n<p>in the last few days I switched to use Caffe for CNN. The problem now is how to get predictions? I know there is another post about probabilities but it wasn't helpful for me.</p>\n<p>any one has easy to follow python code to get probabilities from caffe for this competition and like to share it?</p>\n<p>thanks in advance</p>",
  "messages": [
    {
      "id": "65920",
      "postDate": "03/10/2015 21:46:50",
      "content": "<p>Hi&nbsp;</p>\n<p>in the last few days I switched to use Caffe for CNN. The problem now is how to get predictions? I know there is another post about probabilities but it wasn't helpful for me.</p>\n<p>any one has easy to follow python code to get probabilities from caffe for this competition and like to share it?</p>\n<p>thanks in advance</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65923",
      "postDate": "03/10/2015 22:57:00",
      "content": "<p>I do something like this:</p>\n<p><code>import caffe</code></p>\n<p><code>import os<code></code></code></p>\n<p><code><code></code>MODEL_FILE = 'plankton_full_deploy.prototxt'</code></p>\n<p><code>PRETRAINED =&nbsp; 'checkpoints/plankton_full_iter_1000000.caffemodel'</code></p>\n<p><code>TESTPATH = '../data/test/'</code></p>\n<p><code>blob = caffe.proto.caffe_pb2.BlobProto()</code></p>\n<p><code>data = open('../data/test_mean.binaryproto','rb').read()</code></p>\n<p><code>blob.ParseFromString(data)</code><code></code></p>\n<p><code>arr = np.array(caffe.io.blobproto_to_array(blob))</code><code></code></p>\n<p><code>net = caffe.Classifier(MODEL_FILE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRETRAINED,</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mean=arr[0],</code><code>&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raw_scale=255,</code><code>&nbsp;&nbsp;&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image_dims=(70,70))</code></p>\n<p><code>net.set_phase_test()</code><code>net.set_mode_gpu()</code></p>\n<p><code>for root, dirs, files in os.walk(TESTPATH):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp; for name in files:</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if name.endswith((&quot;.jpg&quot;)):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image = caffe.io.load_image(os.path.join(root,name))<br></code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; predictions = net.predict(image)</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out = [p for p in predictions]</code><code></code><code></code></p>\n<p>out will then be a list containing the class probabilities.&nbsp; This will run slowly though as I have missed out some of the details on how I do this in batches of images, but this should be enough to show the basic method.&nbsp; Good luck!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65924",
      "postDate": "03/10/2015 23:04:07",
      "content": "<p>See</p>\n<p>http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/classification.ipynb</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65925",
      "postDate": "03/10/2015 23:35:55",
      "content": "<p>Thanks guys for respond. I will try my best.</p>\n<p>Good Luck</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65966",
      "postDate": "03/11/2015 16:53:15",
      "content": "<p>Senecaur</p>\n<p>in the deployment model:&nbsp;plankton_full_deploy.prototxt what is the value u are setting for the number of channels?</p>\n<p>Because our images are gray scale I am putting 1 but it is making an error. when I put 3 it worked</p>\n<p>is there any setting I should consider to overcome this problem?</p>\n<p>another question what is the rule of mean file? If I train the network without mean file&nbsp;mean_file: &quot;average.png&quot; is my solution is right. btw I tried the code to load average.png but didn't work</p>\n\n<p>please it is so important to get answer. I just one to do at least one submission using CNN</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65973",
      "postDate": "03/11/2015 19:02:45",
      "content": "<p>Hi,</p>\n<p>I also had an error about channels not matching first. In https://github.com/BVLC/caffe/issues/462 you find a modification for the python wrapper to handle one-channel input. If you create your leveldb/lmdb database with the convert_imageset function, you can pass a &quot;-gray&quot; flag to treat everything as grayscale. Using those two solved the channel error for me.</p>\n<p>Best, Matthias</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65975",
      "postDate": "03/11/2015 19:28:00",
      "content": "<p>Hi,</p>\n<p>Function&nbsp; caffe.io.load_image(os.path.join(root,name)) return&nbsp;image with&nbsp;3 channels by default. You can use parameter color=False in order to process grayscale. More details you can find in $CAFFE_ROOT/python/caffe/io.py</p>\n<p>If you didn't use mean file during training you can set mean=None. By the way. &quot;None&quot; is a default value for mean.</p>\n<p>Best regards, Oleksandr.</p>\n<p>[quote=Data-Lover;65966]</p>\n<p>Senecaur</p>\n<p>in the deployment model:&nbsp;plankton_full_deploy.prototxt what is the value u are setting for the number of channels?</p>\n<p>Because our images are gray scale I am putting 1 but it is making an error. when I put 3 it worked</p>\n<p>is there any setting I should consider to overcome this problem?</p>\n<p>another question what is the rule of mean file? If I train the network without mean file&nbsp;mean_file: &quot;average.png&quot; is my solution is right. btw I tried the code to load average.png but didn't work</p>\n<p>please it is so important to get answer. I just one to do at least one submission using CNN</p>\n<p>[/quote]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "65982",
      "postDate": "03/11/2015 20:54:58",
      "content": "<p>Thanks guys for respond</p>\n<p>I dont have problem with reading images in gray scale. I have problem with building the net</p>\n<p>net = caffe.Classifier(model..., depl...)</p>\n<p>in the train test phase i read the images as&nbsp;type: IMAGE_DATA the training passed very well&nbsp;</p>\n<p>but when I come to deployment I set the channels&nbsp;</p>\n<p>input_dim: 10<br>input_dim:&nbsp;1<br>input_dim: 48<br>input_dim: 48</p>\n<p>the problem now is caffe complain that channel number should be 3 when I changed input_dim: 3</p>\n<p>it worked. I think it is as you said changing data to leveldb will solve the problem</p>\n<p>if you can post the code u use for converting images to levelDB and compute image mean&nbsp;it would be great.&nbsp;learning&nbsp;caffe in few days is a big headach.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "66002",
      "postDate": "03/12/2015 05:42:02",
      "content": "<p>try this:</p>\n<p>https://github.com/BVLC/caffe/issues/391</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "66078",
      "postDate": "03/13/2015 04:58:35",
      "content": "<p>Hi, may i know what is your last layer? Is it softmax, softmax seems gives 1s 0s only.</p>\n\n<p>[quote=Senecaur;65923]</p>\n<p>I do something like this:</p>\n<p><code>import caffe</code></p>\n<p><code>import os<code></code></code></p>\n<p><code><code></code>MODEL_FILE = 'plankton_full_deploy.prototxt'</code></p>\n<p><code>PRETRAINED =&nbsp; 'checkpoints/plankton_full_iter_1000000.caffemodel'</code></p>\n<p><code>TESTPATH = '../data/test/'</code></p>\n<p><code>blob = caffe.proto.caffe_pb2.BlobProto()</code></p>\n<p><code>data = open('../data/test_mean.binaryproto','rb').read()</code></p>\n<p><code>blob.ParseFromString(data)</code><code></code></p>\n<p><code>arr = np.array(caffe.io.blobproto_to_array(blob))</code><code></code></p>\n<p><code>net = caffe.Classifier(MODEL_FILE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRETRAINED,</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mean=arr[0],</code><code>&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raw_scale=255,</code><code>&nbsp;&nbsp;&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image_dims=(70,70))</code></p>\n<p><code>net.set_phase_test()</code><code>net.set_mode_gpu()</code></p>\n<p><code>for root, dirs, files in os.walk(TESTPATH):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp; for name in files:</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if name.endswith((&quot;.jpg&quot;)):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image = caffe.io.load_image(os.path.join(root,name))<br></code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; predictions = net.predict(image)</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out = [p for p in predictions]</code><code></code><code></code></p>\n<p>out will then be a list containing the class probabilities.&nbsp; This will run slowly though as I have missed out some of the details on how I do this in batches of images, but this should be enough to show the basic method.&nbsp; Good luck!</p>\n<p>[/quote]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "66080",
      "postDate": "03/13/2015 05:28:44",
      "content": "<p>I am using this code and it is working well but the problem my network architecture is not good so am getting high error rate but at least it is working</p>\n<p>in training file</p>\n<p>layers<br>{<br> name: &quot;loss&quot;<br> type: SOFTMAX_LOSS<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;loss&quot;<br>}<br> <br> <br> <br>layers <br>{<br> name: &quot;accuracy&quot;<br> type: ACCURACY<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;accuracy&quot;<br> <br> include: { phase: TEST }<br>}</p>\n\n<p>in deployment file</p>\n<p>layers<br>{<br> name: &quot;prob&quot;<br> type: SOFTMAX<br> <br> bottom: &quot;fully3&quot;<br> top: &quot;prob&quot;<br>}</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "66083",
      "postDate": "03/13/2015 07:00:54",
      "content": "<p>Thanks, I am going to try it out.</p>\n\n<p>[quote=Data-Lover;66080]</p>\n<p>I am using this code and it is working well but the problem my network architecture is not good so am getting high error rate but at least it is working</p>\n<p>in training file</p>\n<p>layers<br>{<br> name: &quot;loss&quot;<br> type: SOFTMAX_LOSS<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;loss&quot;<br>}<br> <br> <br> <br>layers <br>{<br> name: &quot;accuracy&quot;<br> type: ACCURACY<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;accuracy&quot;<br> <br> include: { phase: TEST }<br>}</p>\n<p>in deployment file</p>\n<p>layers<br>{<br> name: &quot;prob&quot;<br> type: SOFTMAX<br> <br> bottom: &quot;fully3&quot;<br> top: &quot;prob&quot;<br>}</p>\n<p>[/quote]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "161361",
      "postDate": "02/13/2017 10:59:43",
      "content": "<p>I am getting very slow iteration rate.I can use only cpu mode please help.\n Iteration 0 (-5.62061e-42 iter/s, 6071.5s/50 iters), loss = 0.838223\nUsing 4cpu 23gbram google cloud server.</p>",
      "rawMarkdown": "I am getting very slow iteration rate.I can use only cpu mode please help.\n Iteration 0 (-5.62061e-42 iter/s, 6071.5s/50 iters), loss = 0.838223\nUsing 4cpu 23gbram google cloud server.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 65923,
      "author_name": "senecaur",
      "author_url": "",
      "post_date": "03/10/2015 22:57:00",
      "content": "<p>I do something like this:</p>\n<p><code>import caffe</code></p>\n<p><code>import os<code></code></code></p>\n<p><code><code></code>MODEL_FILE = 'plankton_full_deploy.prototxt'</code></p>\n<p><code>PRETRAINED =&nbsp; 'checkpoints/plankton_full_iter_1000000.caffemodel'</code></p>\n<p><code>TESTPATH = '../data/test/'</code></p>\n<p><code>blob = caffe.proto.caffe_pb2.BlobProto()</code></p>\n<p><code>data = open('../data/test_mean.binaryproto','rb').read()</code></p>\n<p><code>blob.ParseFromString(data)</code><code></code></p>\n<p><code>arr = np.array(caffe.io.blobproto_to_array(blob))</code><code></code></p>\n<p><code>net = caffe.Classifier(MODEL_FILE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRETRAINED,</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mean=arr[0],</code><code>&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raw_scale=255,</code><code>&nbsp;&nbsp;&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image_dims=(70,70))</code></p>\n<p><code>net.set_phase_test()</code><code>net.set_mode_gpu()</code></p>\n<p><code>for root, dirs, files in os.walk(TESTPATH):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp; for name in files:</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if name.endswith((&quot;.jpg&quot;)):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image = caffe.io.load_image(os.path.join(root,name))<br></code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; predictions = net.predict(image)</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out = [p for p in predictions]</code><code></code><code></code></p>\n<p>out will then be a list containing the class probabilities.&nbsp; This will run slowly though as I have missed out some of the details on how I do this in batches of images, but this should be enough to show the basic method.&nbsp; Good luck!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65924,
      "author_name": "cydonia",
      "author_url": "",
      "post_date": "03/10/2015 23:04:07",
      "content": "<p>See</p>\n<p>http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/classification.ipynb</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65925,
      "author_name": "",
      "author_url": "",
      "post_date": "03/10/2015 23:35:55",
      "content": "<p>Thanks guys for respond. I will try my best.</p>\n<p>Good Luck</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65966,
      "author_name": "",
      "author_url": "",
      "post_date": "03/11/2015 16:53:15",
      "content": "<p>Senecaur</p>\n<p>in the deployment model:&nbsp;plankton_full_deploy.prototxt what is the value u are setting for the number of channels?</p>\n<p>Because our images are gray scale I am putting 1 but it is making an error. when I put 3 it worked</p>\n<p>is there any setting I should consider to overcome this problem?</p>\n<p>another question what is the rule of mean file? If I train the network without mean file&nbsp;mean_file: &quot;average.png&quot; is my solution is right. btw I tried the code to load average.png but didn't work</p>\n\n<p>please it is so important to get answer. I just one to do at least one submission using CNN</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65973,
      "author_name": "",
      "author_url": "",
      "post_date": "03/11/2015 19:02:45",
      "content": "<p>Hi,</p>\n<p>I also had an error about channels not matching first. In https://github.com/BVLC/caffe/issues/462 you find a modification for the python wrapper to handle one-channel input. If you create your leveldb/lmdb database with the convert_imageset function, you can pass a &quot;-gray&quot; flag to treat everything as grayscale. Using those two solved the channel error for me.</p>\n<p>Best, Matthias</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65975,
      "author_name": "obaiev",
      "author_url": "",
      "post_date": "03/11/2015 19:28:00",
      "content": "<p>Hi,</p>\n<p>Function&nbsp; caffe.io.load_image(os.path.join(root,name)) return&nbsp;image with&nbsp;3 channels by default. You can use parameter color=False in order to process grayscale. More details you can find in $CAFFE_ROOT/python/caffe/io.py</p>\n<p>If you didn't use mean file during training you can set mean=None. By the way. &quot;None&quot; is a default value for mean.</p>\n<p>Best regards, Oleksandr.</p>\n<p>[quote=Data-Lover;65966]</p>\n<p>Senecaur</p>\n<p>in the deployment model:&nbsp;plankton_full_deploy.prototxt what is the value u are setting for the number of channels?</p>\n<p>Because our images are gray scale I am putting 1 but it is making an error. when I put 3 it worked</p>\n<p>is there any setting I should consider to overcome this problem?</p>\n<p>another question what is the rule of mean file? If I train the network without mean file&nbsp;mean_file: &quot;average.png&quot; is my solution is right. btw I tried the code to load average.png but didn't work</p>\n<p>please it is so important to get answer. I just one to do at least one submission using CNN</p>\n<p>[/quote]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 65982,
      "author_name": "",
      "author_url": "",
      "post_date": "03/11/2015 20:54:58",
      "content": "<p>Thanks guys for respond</p>\n<p>I dont have problem with reading images in gray scale. I have problem with building the net</p>\n<p>net = caffe.Classifier(model..., depl...)</p>\n<p>in the train test phase i read the images as&nbsp;type: IMAGE_DATA the training passed very well&nbsp;</p>\n<p>but when I come to deployment I set the channels&nbsp;</p>\n<p>input_dim: 10<br>input_dim:&nbsp;1<br>input_dim: 48<br>input_dim: 48</p>\n<p>the problem now is caffe complain that channel number should be 3 when I changed input_dim: 3</p>\n<p>it worked. I think it is as you said changing data to leveldb will solve the problem</p>\n<p>if you can post the code u use for converting images to levelDB and compute image mean&nbsp;it would be great.&nbsp;learning&nbsp;caffe in few days is a big headach.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 66002,
      "author_name": "zerozero",
      "author_url": "",
      "post_date": "03/12/2015 05:42:02",
      "content": "<p>try this:</p>\n<p>https://github.com/BVLC/caffe/issues/391</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 66078,
      "author_name": "stevendu",
      "author_url": "",
      "post_date": "03/13/2015 04:58:35",
      "content": "<p>Hi, may i know what is your last layer? Is it softmax, softmax seems gives 1s 0s only.</p>\n\n<p>[quote=Senecaur;65923]</p>\n<p>I do something like this:</p>\n<p><code>import caffe</code></p>\n<p><code>import os<code></code></code></p>\n<p><code><code></code>MODEL_FILE = 'plankton_full_deploy.prototxt'</code></p>\n<p><code>PRETRAINED =&nbsp; 'checkpoints/plankton_full_iter_1000000.caffemodel'</code></p>\n<p><code>TESTPATH = '../data/test/'</code></p>\n<p><code>blob = caffe.proto.caffe_pb2.BlobProto()</code></p>\n<p><code>data = open('../data/test_mean.binaryproto','rb').read()</code></p>\n<p><code>blob.ParseFromString(data)</code><code></code></p>\n<p><code>arr = np.array(caffe.io.blobproto_to_array(blob))</code><code></code></p>\n<p><code>net = caffe.Classifier(MODEL_FILE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRETRAINED,</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mean=arr[0],</code><code>&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raw_scale=255,</code><code>&nbsp;&nbsp;&nbsp;</code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image_dims=(70,70))</code></p>\n<p><code>net.set_phase_test()</code><code>net.set_mode_gpu()</code></p>\n<p><code>for root, dirs, files in os.walk(TESTPATH):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp; for name in files:</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if name.endswith((&quot;.jpg&quot;)):</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image = caffe.io.load_image(os.path.join(root,name))<br></code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; predictions = net.predict(image)</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out = [p for p in predictions]</code><code></code><code></code></p>\n<p>out will then be a list containing the class probabilities.&nbsp; This will run slowly though as I have missed out some of the details on how I do this in batches of images, but this should be enough to show the basic method.&nbsp; Good luck!</p>\n<p>[/quote]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 66080,
      "author_name": "",
      "author_url": "",
      "post_date": "03/13/2015 05:28:44",
      "content": "<p>I am using this code and it is working well but the problem my network architecture is not good so am getting high error rate but at least it is working</p>\n<p>in training file</p>\n<p>layers<br>{<br> name: &quot;loss&quot;<br> type: SOFTMAX_LOSS<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;loss&quot;<br>}<br> <br> <br> <br>layers <br>{<br> name: &quot;accuracy&quot;<br> type: ACCURACY<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;accuracy&quot;<br> <br> include: { phase: TEST }<br>}</p>\n\n<p>in deployment file</p>\n<p>layers<br>{<br> name: &quot;prob&quot;<br> type: SOFTMAX<br> <br> bottom: &quot;fully3&quot;<br> top: &quot;prob&quot;<br>}</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 66083,
      "author_name": "stevendu",
      "author_url": "",
      "post_date": "03/13/2015 07:00:54",
      "content": "<p>Thanks, I am going to try it out.</p>\n\n<p>[quote=Data-Lover;66080]</p>\n<p>I am using this code and it is working well but the problem my network architecture is not good so am getting high error rate but at least it is working</p>\n<p>in training file</p>\n<p>layers<br>{<br> name: &quot;loss&quot;<br> type: SOFTMAX_LOSS<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;loss&quot;<br>}<br> <br> <br> <br>layers <br>{<br> name: &quot;accuracy&quot;<br> type: ACCURACY<br> <br> bottom: &quot;fully3&quot;<br> bottom: &quot;label&quot;<br> top: &quot;accuracy&quot;<br> <br> include: { phase: TEST }<br>}</p>\n<p>in deployment file</p>\n<p>layers<br>{<br> name: &quot;prob&quot;<br> type: SOFTMAX<br> <br> bottom: &quot;fully3&quot;<br> top: &quot;prob&quot;<br>}</p>\n<p>[/quote]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 161361,
      "author_name": "karandeepdps",
      "author_url": "",
      "post_date": "02/13/2017 10:59:43",
      "content": "<p>I am getting very slow iteration rate.I can use only cpu mode please help.\n Iteration 0 (-5.62061e-42 iter/s, 6071.5s/50 iters), loss = 0.838223\nUsing 4cpu 23gbram google cloud server.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "65920": "",
    "65923": "",
    "65924": "",
    "65925": "",
    "65966": "",
    "65973": "",
    "65975": "",
    "65982": "",
    "66002": "",
    "66078": "",
    "66080": "",
    "66083": "",
    "161361": "I am getting very slow iteration rate.I can use only cpu mode please help.\n Iteration 0 (-5.62061e-42 iter/s, 6071.5s/50 iters), loss = 0.838223\nUsing 4cpu 23gbram google cloud server."
  },
  "source": "meta"
}