RuntimeError: Unsupported marker type 0x4f on 2nd epoch

username: AntMorais
cooked: <p>Greetings,<br>
I get this error when I train a resnet18 model from Torchvision on a custom dataset. It only happens on the 2nd epoch after a few dozen iterations.</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-63-e338034a4492&gt; in &lt;module&gt;()
----&gt; 1 model_ft = train_model(model_ft, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=25)

8 frames
/usr/local/lib/python3.7/dist-packages/torchvision/io/image.py in decode_image(input, mode)
    200         output (Tensor[image_channels, image_height, image_width])
    201     """
--&gt; 202     output = torch.ops.image.decode_image(input, mode.value)
    203     return output
    204 

RuntimeError: Unsupported marker type 0x4f

</code></pre>
<p>I use these transforms:</p>
<pre><code class="lang-auto">transform = nn.Sequential(
            T.Resize([256, ]), 
            T.CenterCrop(224),
            T.ConvertImageDtype(torch.float),
            T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        )
</code></pre>
<p>Does anyone have an idea of what could be wrong?</p>

username: ptrblck
cooked: <p>The image decoding is failing and <code>torchvision</code> seems to reraise the error. Are you able to load the file with another library and if so, could you save it using a different file name, and try to load it again via <code>torch.ops.image.decode_image</code>?</p>

username: AntMorais
cooked: <p>I read the image and saved with PIL and it solved the problem. Thanks!</p>
<pre><code class="lang-auto">p = 'wikiart/Post_Impressionism/vincent-van-gogh_l-arlesienne-portrait-of-madame-ginoux-1890.jpg'
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open(p) as im:
    im.save(p)
</code></pre>
<p>Here is the image for context:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/b/ab10388c2a29d12227ab7688d1a71ed6af06141b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/ab10388c2a29d12227ab7688d1a71ed6af06141b" title="Unknown"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab10388c2a29d12227ab7688d1a71ed6af06141b_2_383x500.jpeg" alt="Unknown" data-base62-sha1="opioPG36mSTB8vPykqUXFw94Sxl" width="383" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab10388c2a29d12227ab7688d1a71ed6af06141b_2_383x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab10388c2a29d12227ab7688d1a71ed6af06141b_2_574x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab10388c2a29d12227ab7688d1a71ed6af06141b_2_766x1000.jpeg 2x" data-dominant-color="9B968C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Unknown</span><span class="informations">900×1172 79.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>