{
  "id": 4453,
  "title": "Error when running lcn.py",
  "url": "/competitions/challenges-in-representation-learning-multi-modal-learning/discussion/4453",
  "author_name": "",
  "post_date": "2013-04-27T09:03:30.523Z",
  "votes": null,
  "comment_count": 5,
  "views": 2402,
  "content": "<pre>I run the commandTHEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python lcn.py public_test</pre>\r\n<pre>And it shows this, </pre>\r\n<pre>I viewed the picture mannually, it is correct.</pre>\r\n<pre>How to fix it?</pre>\r\n<pre>Thanks.</pre>\r\n<pre>&lt;PIL.PngImagePlugin.PngImageFile image mode=RGB size=300x200 at 0x75EFF80&gt;<br>(300, 200)<br>Traceback (most recent call last):<br>  File &quot;lcn.py&quot;, line 93, in &lt;module&gt;<br>    img = image.load(path)<br>  File &quot;/usr/local/lib/python2.7/site-packages/pylearn2-0.1dev-py2.7.egg/pylearn2/utils/image.py&quot;, line 279, in load<br>    str(numpy_rval.ndim)&#43;&quot; dimensions. Expected 2 or 3.&quot;<br>AssertionError: Tried to load an image, got an array with 0 dimensions. Expected 2 or 3.This may indicate a mildly corrupted image file. Try converting it to a different image format with a different editor like gimp or imagemagic. Sometimes these programs are more robust to minor corruption than PIL and will emit a correctly formatted image in the new format.</pre>",
  "messages": [
    {
      "id": "23548",
      "postDate": "04/27/2013 09:03:30",
      "content": "<pre>I run the commandTHEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python lcn.py public_test</pre>\r\n<pre>And it shows this, </pre>\r\n<pre>I viewed the picture mannually, it is correct.</pre>\r\n<pre>How to fix it?</pre>\r\n<pre>Thanks.</pre>\r\n<pre>&lt;PIL.PngImagePlugin.PngImageFile image mode=RGB size=300x200 at 0x75EFF80&gt;<br>(300, 200)<br>Traceback (most recent call last):<br>  File &quot;lcn.py&quot;, line 93, in &lt;module&gt;<br>    img = image.load(path)<br>  File &quot;/usr/local/lib/python2.7/site-packages/pylearn2-0.1dev-py2.7.egg/pylearn2/utils/image.py&quot;, line 279, in load<br>    str(numpy_rval.ndim)&#43;&quot; dimensions. Expected 2 or 3.&quot;<br>AssertionError: Tried to load an image, got an array with 0 dimensions. Expected 2 or 3.This may indicate a mildly corrupted image file. Try converting it to a different image format with a different editor like gimp or imagemagic. Sometimes these programs are more robust to minor corruption than PIL and will emit a correctly formatted image in the new format.</pre>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "23586",
      "postDate": "04/28/2013 19:42:18",
      "content": "<p>I'm not sure what's going on here.</p>\r\n<p>This error message usually appears when a file wasn't formatted quite according to the png specification. Viewing it manually doesn't really tell you anything--a lot of image viewing programs are more robust to slight deviations from the png specification\r\n than PIL is, and this piece of code depends on PIL. However, if you're running this on the test images I prepared, they should all be formatted exactly according to the png specification and should be fully PIL-compatible.</p>\r\n<p>Do you know what the path to the image is?</p>\r\n<p>What happens if you open a python shell and run</p>\r\n<p>from PIL import Image</p>\r\n<p>import numpy as np</p>\r\n<p>pil_image = Image.open(filepath) # fill in the right value for filepath here</p>\r\n<p>np_image = np.array(pil_image)</p>\r\n<p>print np_image.shape</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "23618",
      "postDate": "04/29/2013 12:58:24",
      "content": "<p>Hi Ian,</p>\r\n<p>Sorry to disturb you again. Here is my result in Linux:</p>\r\n<p>[root] ls</p>\r\n<p>......</p>\r\n<pre>134.png  16.png   204.png  23.png   275.png  30.png   345.png  380.png  415.png  450.png  486.png  70.png<br>[root@localhost public_test_images]# python<br>Python 2.7.4 (default, Apr 24 2013, 22:11:09)<br>[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; from PIL import Image<br>&gt;&gt;&gt; import numpy as np<br>&gt;&gt;&gt; pil_image = Image.open(&quot;2.png&quot;)<br>&gt;&gt;&gt; np_image = np.array(pil_image)<br>&gt;&gt;&gt; print np_image.shape<br>()<br>&gt;&gt;&gt;</pre>\r\n<pre>&nbsp;</pre>\r\n<pre>And in Windows, the PIL works correct: (300, 300, 3)</pre>\r\n<pre>I transformed it to BMP in windows then copy to Linux machine, the PIL works correct when loading the BMP image.</pre>\r\n<pre>&gt;&gt;&gt; pil_image = Image.open(&quot;3.bmp&quot;)<br>&gt;&gt;&gt; np_image = np.array(pil_image)<br>&gt;&gt;&gt; print np_image.shape<br>(300, 300, 3)</pre>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "23634",
      "postDate": "04/29/2013 16:26:26",
      "content": "<p>OK, it does look like something is wrong with your installation of PIL. I'm afraid I don't know a lot about how to fix that.</p>\r\n<p>You can check your PIL version by doing</p>\r\n<p>from PIL import Image</p>\r\n<p>print Image.VERSION</p>\r\n<p>Mine is 1.1.7. If yours is older than that, maybe consider updating it.</p>\r\n<p>I guess it could be the numpy version too. I'm using 1.6.1.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "23636",
      "postDate": "04/29/2013 16:31:02",
      "content": "<p>Same software version as you....</p>\r\n<p>I fix it very dirty... By using pickle dumps in Windows and loads in Linux...</p>\r\n<p>Anyway, thank you Ian!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "23641",
      "postDate": "04/29/2013 16:55:03",
      "content": "<p>And decent solution:</p>\r\n<p>easy_install pillow</p>\r\n<p>:)</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 23586,
      "author_name": "iangoodfellow",
      "author_url": "",
      "post_date": "04/28/2013 19:42:18",
      "content": "<p>I'm not sure what's going on here.</p>\r\n<p>This error message usually appears when a file wasn't formatted quite according to the png specification. Viewing it manually doesn't really tell you anything--a lot of image viewing programs are more robust to slight deviations from the png specification\r\n than PIL is, and this piece of code depends on PIL. However, if you're running this on the test images I prepared, they should all be formatted exactly according to the png specification and should be fully PIL-compatible.</p>\r\n<p>Do you know what the path to the image is?</p>\r\n<p>What happens if you open a python shell and run</p>\r\n<p>from PIL import Image</p>\r\n<p>import numpy as np</p>\r\n<p>pil_image = Image.open(filepath) # fill in the right value for filepath here</p>\r\n<p>np_image = np.array(pil_image)</p>\r\n<p>print np_image.shape</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 23618,
      "author_name": "ywu82278",
      "author_url": "",
      "post_date": "04/29/2013 12:58:24",
      "content": "<p>Hi Ian,</p>\r\n<p>Sorry to disturb you again. Here is my result in Linux:</p>\r\n<p>[root] ls</p>\r\n<p>......</p>\r\n<pre>134.png  16.png   204.png  23.png   275.png  30.png   345.png  380.png  415.png  450.png  486.png  70.png<br>[root@localhost public_test_images]# python<br>Python 2.7.4 (default, Apr 24 2013, 22:11:09)<br>[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; from PIL import Image<br>&gt;&gt;&gt; import numpy as np<br>&gt;&gt;&gt; pil_image = Image.open(&quot;2.png&quot;)<br>&gt;&gt;&gt; np_image = np.array(pil_image)<br>&gt;&gt;&gt; print np_image.shape<br>()<br>&gt;&gt;&gt;</pre>\r\n<pre>&nbsp;</pre>\r\n<pre>And in Windows, the PIL works correct: (300, 300, 3)</pre>\r\n<pre>I transformed it to BMP in windows then copy to Linux machine, the PIL works correct when loading the BMP image.</pre>\r\n<pre>&gt;&gt;&gt; pil_image = Image.open(&quot;3.bmp&quot;)<br>&gt;&gt;&gt; np_image = np.array(pil_image)<br>&gt;&gt;&gt; print np_image.shape<br>(300, 300, 3)</pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 23634,
      "author_name": "iangoodfellow",
      "author_url": "",
      "post_date": "04/29/2013 16:26:26",
      "content": "<p>OK, it does look like something is wrong with your installation of PIL. I'm afraid I don't know a lot about how to fix that.</p>\r\n<p>You can check your PIL version by doing</p>\r\n<p>from PIL import Image</p>\r\n<p>print Image.VERSION</p>\r\n<p>Mine is 1.1.7. If yours is older than that, maybe consider updating it.</p>\r\n<p>I guess it could be the numpy version too. I'm using 1.6.1.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 23636,
      "author_name": "ywu82278",
      "author_url": "",
      "post_date": "04/29/2013 16:31:02",
      "content": "<p>Same software version as you....</p>\r\n<p>I fix it very dirty... By using pickle dumps in Windows and loads in Linux...</p>\r\n<p>Anyway, thank you Ian!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 23641,
      "author_name": "ywu82278",
      "author_url": "",
      "post_date": "04/29/2013 16:55:03",
      "content": "<p>And decent solution:</p>\r\n<p>easy_install pillow</p>\r\n<p>:)</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "23548": "",
    "23586": "",
    "23618": "",
    "23634": "",
    "23636": "",
    "23641": ""
  },
  "source": "meta"
}