Image Sizing Is too large when trying to display image from deep learning pipeline

username: Jennifer_Davis
cooked: <p>thanks so much for this forum, its helping me to learn so much!  I will try to answer a few questions as well.  Still being a newbie my question is below.</p>
<p>I am trying to display an image from a deep learning pipeline with the associated label.  The error I am getting is that the image is too large in pixel size.  I am guessing that the labels may be loading incorrectly or somewhere in the pipeline the image is not sized correctly.  I think this because when I try to do something like;</p>
<pre><code class="lang-auto">train_features, label = next(iter(trn_dl))

print(train_features, train_labels)
</code></pre>
<p>It throws an error:</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-56-9b9b1ca99075&gt; in &lt;module&gt;
      1 ##documentation: https://pytorch.org/tutorials/beginner/basics/data_tutorial.html
      2 
----&gt; 3 train_features, labels = next(iter(trn_dl))
      4 
      5 print(train_features, train_labels)

ValueError: too many values to unpack (expected 2)
</code></pre>
<p>However I also get an error when I run the code below, when using directories with multiple levels.  For example if I use a directory a/images. It works okay, but if I use a directory a/b/c/images, I get this type of error.</p>
<p>Here’s my data loading class, and data loader (which seems to work and does not throw and error):</p>
<pre><code class="lang-auto">class CaptioningData(Dataset):
    def __init__(self, root, df, vocab):
        self.df = df.reset_index(drop=True)
        self.root = root
        self.vocab = vocab
        self.id_to_path = dict()
        for dirpath, _, filenames in os.walk(self.root):
            for filename in filenames:
                id, ext = os.path.splitext(filename)
                if ext == '.png':
                    self.id_to_path[id] = os.path.join(dirpath, filename)
        self.transform = transforms.Compose([ 
            transforms.Resize(224),
            transforms.RandomCrop(224),
            transforms.RandomHorizontalFlip(), 
            transforms.ToTensor(), 
            transforms.Normalize((0.485, 0.456, 0.406), 
                                 (0.229, 0.224, 0.225))]
        )
    
    #def __getitem__(self, idx):
    #img_path = os.path.join(self.img_dir, self.img_labels.iloc[idx, 0])
    #image = read_image(img_path)
    #label = self.img_labels.iloc[idx, 1]
    #if self.transform:
    #    image = self.transform(image)
    #if self.target_transform:
    #    label = self.target_transform(label)
    #return image, label
    
    def __getitem__(self, idx): #ORIGINAL says self, index
        """Returns one data pair (image and caption)."""
        row = self.df.iloc[idx].squeeze()
        id = row.image_id
        image = self.id_to_path[id]
        image = Image.open(image).convert('RGB')
        #for id in row.image_id:#DEBUG
        #    caption = row.InChI #DEBUG
        caption = row.InChI # here need caption to match image_id
        #tokens = str(caption).lower().split()
        tokens = caption.split()
        target = []
        target.append(vocab.stoi['&lt;start&gt;'])
        target.extend([vocab.stoi[token] for token in tokens]) #this line is a problem as each caption is one token
        target.append(vocab.stoi['&lt;end&gt;'])
        target = torch.Tensor(target).long()
        return image, target, caption
    
    #debug
    def choose(self):
        return self[np.random.randint(len(self))]

    def __len__(self):
        return len(self.df)
    
    def collate_fn(self, data):
        data.sort(key=lambda x: len(x[1]), reverse=True)
        images, targets, captions = zip(*data)
        images = torch.stack([self.transform(image) for image in images], 0)
        lengths = [len(tar) for tar in targets]
        _targets = torch.zeros(len(captions), max(lengths)).long()
        for i, tar in enumerate(targets):
            end = lengths[i]
            _targets[i, :end] = tar[:end] 
        return images.to(device), _targets.to(device), torch.tensor(lengths).long().to(device)
</code></pre>
<p>However at the end of my pipeline I use the following code to display and retrieve the image and image labels and I get this error (code I’m using is shown first).</p>
<pre><code class="lang-auto">def load_image(image_path, transform=True): #original is none, debug is True
    image = Image.open(image_path).convert('RGB') #original
    image = image.resize([224, 224], Image.LANCZOS)
    if transform is not None:
        tfm_image = transform(image)[None]
    return image, tfm_image

@torch.no_grad()
def load_image_and_predict(image_path):
    transform = transforms.Compose([
        transforms.ToTensor(), 
        transforms.Normalize((0.485, 0.456, 0.406), 
                             (0.229, 0.224, 0.225))
    ])

    org_image, tfm_image = load_image(image_path, transform)
    image_tensor = tfm_image.to(device)
    encoder.eval()
    decoder.eval()
    feature = encoder(image_tensor)
    sentence = decoder.predict(feature)[0]
    show(org_image, title=sentence)
    return sentence

#files = Glob(DEBUG_TRAIN) #debug code, test should have the same number of files and folders and train
files = Glob(DEBUG_TEST) # instantiated at the start of the code

"""Loop through all files in the pathway, load images and predict captions"""
#try this later if putting files in one directory doesn't help

for _ in range(5):
    load_image_and_predict(choose(files)) 
</code></pre>
<p>Errors it throws are below:</p>
<pre><code class="lang-auto">ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 67861x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 70653x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 70653x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 70653x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 67861x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
</code></pre>
<p>Any suggestions and tips are greatly appreciated.  Again I’m pretty confident about the CaptioningData class, just not the final image and label retrieval.  I get a error saying the image is too large even though I’m resizing the image before trying to retrieve the image and label.</p>

username: Epoching
cooked: <blockquote>
<p>Image size of 67861x302 pixels is too large</p>
</blockquote>
<p>Yikes! (give me a sec to read post again, this seems like an interesting problem!)</p>

username: Epoching
cooked: <p>Does the error show exactly what line it errors-out on? I’m guessing it was on <code>show(orig_image, title=sentence)</code> but I don’t see a function definition for <code>show</code>. Do you have that somewhere by any chance? <img src="https://discuss.pytorch.org/images/emoji/apple/open_mouth.png?v=9" title=":open_mouth:" class="emoji" alt=":open_mouth:"></p>

username: Jennifer_Davis
cooked: <aside class="quote no-group" data-username="Jennifer_Davis" data-post="1" data-topic="125399">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jennifer_davis/48/38619_2.png" class="avatar"> Jennifer_Davis:</div>
<blockquote>
<p><code>train_features, label = next(iter(trn_dl))</code></p>
</blockquote>
</aside>
<p>for the first error it errors on the first line of code.</p>
<p>For the second set of errors, it seems to error out on a torch internal code, i.e.:</p>
<pre><code class="lang-auto">
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)
</code></pre>
<p>thanks for helping me trouble-shoot</p>

username: Epoching
cooked: <p>Regarding the first error:</p>
<pre><code class="lang-auto">ValueError                                Traceback (most recent call last)
&lt;ipython-input-56-9b9b1ca99075&gt; in &lt;module&gt;
      1 ##documentation: https://pytorch.org/tutorials/beginner/basics/data_tutorial.html
      2 
----&gt; 3 train_features, labels = next(iter(trn_dl))
      4 
      5 print(train_features, train_labels)

ValueError: too many values to unpack (expected 2)
</code></pre>
<p>Try using:<br>
<code>train_features, labels, captions = next(iter(trn_dl))</code><br>
instead of<br>
<code>train_features, labels = next(iter(trn_dl))</code></p>
<p>This is because your <code>CaptioningData</code> class’s <code>__getitem__</code> returns 3 things:<br>
<code>return image, target, caption</code></p>
<p>The PyTorch <code>DataLoader</code> will automatically batch everything (all 3) for you <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Jennifer_Davis
cooked: <p>That works for the first error!  Thanks.  Any chance there’s a clue there why the second error is thrown?</p>

username: Epoching
cooked: <p>Hmmm I see, do you have the code for the function <code>show</code> though? I’m curious to see if something in there caused the image size to increase.</p>
<p>The error message is indeed outside of your code (IPython is what basically runs Jupyter I believe, and it’s probably erroring out because it’s having trouble displaying the large image, so I’m thinking that this is also a “logical” error, rather than purely a “runtime” error, in the sense that something accidently bloated the image size up without any problem until it was ready to print/display it 0.0)</p>

username: Jennifer_Davis
cooked: <p>It’s from one of the libraries I’m using.  The first time I use it (see code below) it displays the image and caption.  So I think you’re right, somewhere in the pipeline my image is getting bloated.</p>
<pre><code class="lang-auto">trn_ds = CaptioningData(DEBUG_TRAIN, data[-data['train']], vocab) # debug code uses only validation data
val_ds = CaptioningData(DEBUG_TRAIN, data[-data['train']], vocab)

image, target, caption = trn_ds.choose()
show(image, title=caption, sz=5); print(target)
</code></pre>

username: Jennifer_Davis
cooked: <p>Libraries include the below:</p>
<pre><code class="lang-auto">from torch_snippets import *
import json
import numpy as np
import pandas as pd
import sklearn
import torch
import ray
import torchtext

from string import ascii_lowercase
from torchvision import transforms
from torchtext.legacy.data import Field
from collections import defaultdict
from torchsummary import summary
from torch.nn.utils.rnn import pack_padded_sequence
from torchvision import models
</code></pre>

username: Epoching
cooked: <p>I see, right before <code>show(org_image, title=sentence)</code> inside <code>load_image_and_predict</code>:</p>
<p>Do you printing out the org_image size by adding <code>org_image.size</code> before the <code>show(org_image, title=sentence)</code> line? As well as print the <code>sentence</code> if possible!</p>
<p><code>print(org_image.size, sentence)</code></p>
<p>(What if the caption is soooo long that it creates more image room for it to print the entire content of <code>sentence</code>!)</p>

username: Jennifer_Davis
cooked: <p>You’re right, the caption/sentence is very, very long.  See below:</p>
<pre><code class="lang-auto">(224, 224) InChI=1S/C20H15FN2O5/c1-26-18-11-13(8-9-16(18)28-20(25)17-7-4-10-27-17)12-22-23-19(24)14-5-2-3-6-15(14)21/h2-12H,1H3,(H,23,24)/b22-12- InChI=1S/C14H18N2O4S/c1-4-12-9(2)7-11(14(18)16(12)3)13(17)15-10-5-6-21(19,20)8-10/h5-7,10H,4,8H2,1-3H3,(H,15,17)/t10-/m0/s1 InChI=1S/C18H31NO/c1-5-9-15(4)13-18(19-7-3)16-10-8-11-17(14-16)20-12-6-2/h8,10-11,14-15,18-19H,5-7,9,12-13H2,1-4H3 InChI=1S/C31H40FNO4/c1-30-16-13-23(34)19-21(30)5-8-24-25-9-10-27(31(25,2)17-14-26(24)30)37-29(36)12-11-28(35)33-18-15-20-3-6-22(32)7-4-20/h3-4,6-7,19,24-27H,5,8-18H2,1-2H3,(H,33,35) InChI=1S/C21H24F2N2O/c1-24(21(26)14-16-9-10-18(22)19(23)13-16)15-20(25-11-5-6-12-25)17-7-3-2-4-8-17/h2-4,7-10,13,20H,5-6,11-12,14-15H2,1H3 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C23H15F2NO3/c24-18-8-4-15(5-9-18)14-28-20-3-1-2-16(12-20)13-21-23(27)29-22(26-21)17-6-10-19(25)11-7-17/h1-13H,14H2 InChI=1S/C15H21FN2O2/c1-18(15(19)11-2-5-13(17)10-11)8-9-20-14-6-3-12(16)4-7-14/h3-4,6-7,11,13H,2,5,8-10,17H2,1H3 InChI=1S/C25H32N6O/c1-25(2,3)22-11-23-26-13-19-20-9-6-17(10-21(19)31(23)29-22)30(20)14-16-12-27-28-24(16)15-4-7-18(32)8-5-15/h4-5,7-8,11,13,16-17,20,24,27-28,32H,6,9-10,12,14H2,1-3H3 InChI=1S/C21H24N4O7/c1-3-31-15-9-13(14(10-16(15)32-4-2)25-19(26)21(29)30)17(20(27)28)24-12-7-5-11(6-8-12)18(22)23/h5-10,17,24H,3-4H2,1-2H3,(H3,22,23)(H,25,26)(H,27,28)(H,29,30) InChI=1S/C15H25NO3/c1-11-4-2-3-9-16(10-11)14(17)12-5-7-13(8-6-12)15(18)19/h11-13H,2-10H2,1H3,(H,18,19) InChI=1S/C15H25NO3/c1-11-4-2-3-9-16(10-11)14(17)12-5-7-13(8-6-12)15(18)19/h11-13H,2-10H2,1H3,(H,18,19) InChI=1S/C18H17NO2/c1-3-21-18-7-5-4-6-15(18)16-10-14-9-8-13(2)11-19(14)17(16)12-20/h4-12H,3H2,1-2H3 InChI=1S/C18H25N3/c1-12-8-14(3)15(9-13(12)2)10-19-17-6-5-7-18-16(17)11-20-21(18)4/h8-9,11,17,19H,5-7,10H2,1-4H3 InChI=1S/C21H24F3N3O3S/c1-14-5-11-18(12-6-14)31(29,30)26-13-15(2)27(20(28)21(22,23)24)19(26)16-7-9-17(10-8-16)25(3)4/h5-12,15,19H,13H2,1-4H3 InChI=1S/C25H32N6O/c1-25(2,3)22-11-23-26-13-19-20-9-6-17(10-21(19)31(23)29-22)30(20)14-16-12-27-28-24(16)15-4-7-18(32)8-5-15/h4-5,7-8,11,13,16-17,20,24,27-28,32H,6,9-10,12,14H2,1-3H3 InChI=1S/C13H16N2O3S/c1-5-18-12(17)9-14-10(16)8-7(13(2,3)4)6-19-11(8)15-9/h6H,5H2,1-4H3,(H,14,15,16) InChI=1S/C12H20N4O/c1-9(2)8-14-12(17)6-7-13-11-5-4-10(3)15-16-11/h4-5,9H,6-8H2,1-3H3,(H,13,16)(H,14,17) InChI=1S/C10H9FN2OS/c11-7-1-2-9-6(3-7)4-8(15-9)5-10(12)13-14/h1-4,14H,5H2,(H2,12,13) InChI=1S/C12H21N3O3/c1-12(2,3)15-11(16)9(6-13)7-14-8-10(17-4)18-5/h7,10,14H,8H2,1-5H3,(H,15,16)/b9-7- InChI=1S/C15H21NO2/c1-4-16(13-9-10-13)15(3,14(17)18)12-7-5-11(2)6-8-12/h5-8,13H,4,9-10H2,1-3H3,(H,17,18) InChI=1S/C24H54N2O3Si/c1-5-9-10-11-12-13-14-15-16-17-18-20-25-22-23-26-21-19-24-30(27-6-2,28-7-3)29-8-4/h25-26H,5-24H2,1-4H3 InChI=1S/C28H31N5O3/c1-35-25-11-10-23(18-26(25)36-2)30-27(34)21-12-16-31(17-13-21)20-22-19-29-33(24-8-4-3-5-9-24)28(22)32-14-6-7-15-32/h3-11,14-15,18-19,21H,12-13,16-17,20H2,1-2H3,(H,30,34) InChI=1S/C22H18F2N4O2/c23-22(24)9-11-28(21(29)18-12-17-16(26-18)6-3-10-25-17)13-19(22)30-20-8-7-14-4-1-2-5-15(14)27-20/h1-8,10,12,19,26H,9,11,13H2 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C28H28N2O4S/c1-5-33-27(31)23-17(3)29-18(4)24(28(32)34-6-2)25(23)20-14-10-11-15-21(20)26-30-22(16-35-26)19-12-8-7-9-13-19/h7-16,25,29H,5-6H2,1-4H3 InChI=1S/C36H39F4N3O3S2/c1-4-6-26-21-30(15-16-32(26)46-24(3)35(44)45-5-2)47-23-33-31(41-34(48-33)25-7-9-27(10-8-25)36(38,39)40)22-42-17-19-43(20-18-42)29-13-11-28(37)12-14-29/h7-16,21,24H,4-6,17-20,22-23H2,1-3H3 InChI=1S/C10H15Cl2N3O2/c1-16-10-14-7-8(12)9(15-10)13-4-2-5-17-6-3-11/h7H,2-6H2,1H3,(H,13,14,15) InChI=1S/C19H28O/c1-4-6-7-8-9-13-16-20-19(17(3)5-2)18-14-11-10-12-15-18/h10-12,14-15,19H,2,4,6-9,13,16H2,1,3H3 InChI=1S/C17H24N2O2/c1-18-16(21)13-15(14-5-3-2-4-6-14)17(18)7-9-19(10-8-17)11-12-20/h2-6,15,20H,7-13H2,1H3/t15-/m1/s1 InChI=1S/C19H19NO4S/c1-11(2)23-15-7-6-13(10-16(15)22-4)9-14-19(21)24-18(20-14)17-8-5-12(3)25-17/h5-11H,1-4H3/b14-9- InChI=1S/C20H24N2O2/c1-15-4-6-17(7-5-15)22-11-12-23-20-18(22)8-9-19(20)24-14-16-3-2-10-21-13-16/h2-7,10,13,18-20H,8-9,11-12,14H2,1H3/t18-,19-,20+/m0/s1 InChI=1S/C18H26FN3O2/c19-17-7-2-1-5-15(17)13-20-18(23)22-9-4-8-21(10-11-22)14-16-6-3-12-24-16/h1-2,5,7,16H,3-4,6,8-14H2,(H,20,23) InChI=1S/C18H34O5/c1-2-3-4-5-6-7-8-9-10-11-12-22-18-16(21)14-23-17(18)15(20)13-19/h7-8,15-21H,2-6,9-14H2,1H3/b8-7+/t15-,16+,17+,18+/m0/s1 InChI=1S/C14H18N4O/c1-10-8-13(18(2)17-10)16-14(19)9-12(15)11-6-4-3-5-7-11/h3-8,12H,9,15H2,1-2H3,(H,16,19) InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C21H21N5O2S/c1-15-7-8-18(17-5-4-11-22-20(15)17)29(27,28)25-13-9-16(10-14-25)21-24-23-19-6-2-3-12-26(19)21/h2-8,11-12,16H,9-10,13-14H2,1H3 InChI=1S/C11H22N2O3/c1-10(2,3-4-14)6-13-11(5-9(15)16)7-12-8-11/h12-14H,3-8H2,1-2H3,(H,15,16) InChI=1S/C17H21N3O5S/c1-10(2)9-25-16(23)14-11(3)18-17(26-14)19-13(21)8-20-7-5-6-12(24-4)15(20)22/h5-7,10H,8-9H2,1-4H3,(H,18,19,21) InChI=1S/C17H21N3O5S/c1-10(2)9-25-16(23)14-11(3)18-17(26-14)19-13(21)8-20-7-5-6-12(24-4)15(20)22/h5-7,10H,8-9H2,1-4H3,(H,18,19,21) InChI=1S/C31H32N6O4S/c1-20(2)19-41-29(38)18-37(42(39,40)27-8-4-6-22-7-5-15-34-30(22)27)24-13-14-26-25(17-24)35-28(36(26)3)16-21-9-11-23(12-10-21)31(32)33/h4-15,17,20H,16,18-19H2,1-3H3,(H3,32,33) InChI=1S/C20H24N2O2/c1-15-4-6-17(7-5-15)22-11-12-23-20-18(22)8-9-19(20)24-14-16-3-2-10-21-13-16/h2-7,10,13,18-20H,8-9,11-12,14H2,1H3/t18-,19-,20+/m0/s1 InChI=1S/C17H18BrClFNO2/c1-11(22)8-21-9-13-6-14(18)3-5-17(13)23-10-12-2-4-15(20)7-16(12)19/h2-7,11,21-22H,8-10H2,1H3/t11-/m0/s1 InChI=1S/C48H96N4O5/c1-4-7-10-13-16-25-32-42-56-47(54)36-28-21-17-23-30-38-51(40-33-41-52(50)43-45(49)44-53)39-31-24-18-22-29-37-48(55)57-46(34-26-19-14-11-8-5-2)35-27-20-15-12-9-6-3/h43,46,53H,4-42,44,49-50H2,1-3H3/b45-43- InChI=1S/C18H30N2O3/c1-2-23-18(22)16-9-12-20(13-10-16)14-17(21)19-11-8-15-6-4-3-5-7-15/h6,16H,2-5,7-14H2,1H3,(H,19,21) InChI=1S/C22H25NO5S/c1-29(26,27)20-14-12-17(13-15-20)22(25)28-16-21(24)23(18-8-4-2-5-9-18)19-10-6-3-7-11-19/h2,4-5,8-9,12-15,19H,3,6-7,10-11,16H2,1H3 InChI=1S/C31H35F2N5O3/c1-19-27(26-22(33)12-20(32)13-23(26)35-29(19)38-17-30(2,3)15-25(38)39)37-18-31(4-8-40-9-5-31)28-24(37)14-21(16-34-28)36-6-10-41-11-7-36/h12-14,16H,4-11,15,17-18H2,1-3H3 InChI=1S/C31H35F2N5O3/c1-19-27(26-22(33)12-20(32)13-23(26)35-29(19)38-17-30(2,3)15-25(38)39)37-18-31(4-8-40-9-5-31)28-24(37)14-21(16-34-28)36-6-10-41-11-7-36/h12-14,16H,4-11,15,17-18H2,1-3H3 InChI=1S/C18H22N6O/c1-13(11-24-15(3)8-14(2)22-24)9-21-18(25)16-4-5-17(20-10-16)23-7-6-19-12-23/h4-8,10,12-13H,9,11H2,1-3H3,(H,21,25)/t13-/m0/s1 InChI=1S/C24H28ClN3O3/c1-17-5-7-18(8-6-17)22(27-9-11-31-12-10-27)15-26-24(30)19-13-23(29)28(16-19)21-4-2-3-20(25)14-21/h2-8,14,19,22H,9-13,15-16H2,1H3,(H,26,30) InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C21H31N5O3S/c1-16(2)13-22-19(27)14-24-8-10-25(11-9-24)15-26-21(30)29-20(23-26)12-17-4-6-18(28-3)7-5-17/h4-7,16H,8-15H2,1-3H3,(H,22,27) InChI=1S/C13H19NO4S/c1-4-10(2)14-13(15)9-18-11-5-7-12(8-6-11)19(3,16)17/h5-8,10H,4,9H2,1-3H3,(H,14,15) InChI=1S/C24H30ClN3O2/c1-3-18(4-2)24(29)26-15-14-23-27-20-11-6-7-12-21(20)28(23)16-9-17-30-22-13-8-5-10-19(22)25/h5-8,10-13,18H,3-4,9,14-17H2,1-2H3,(H,26,29) InChI=1S/C31H29F2N3O/c1-2-3-9-28-35-31(16-4-5-17-31)30(37)36(28)20-21-10-12-22(13-11-21)26-18-23(14-15-24(26)19-34)25-7-6-8-27(32)29(25)33/h6-8,10-15,18H,2-5,9,16-17,20H2,1H3 InChI=1S/C12H12O3S/c1-15-12(14)7-6-11(13)10-4-2-9(8-16)3-5-10/h2-5,8H,6-7H2,1H3 InChI=1S/C21H20ClFN4O7S/c1-26(31)17(10-11-27-19(28)12-18(22)24-21(27)30)20(29)25-35(32,33)16-8-6-15(7-9-16)34-14-4-2-13(23)3-5-14/h2-9,12,17,31H,10-11H2,1H3,(H,24,30)(H,25,29)/t17-/m0/s1 InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C14H18N2O3/c1-9(6-13(17)18)16-14(19)15-8-11-7-10-4-2-3-5-12(10)11/h2-5,9,11H,6-8H2,1H3,(H,17,18)(H2,15,16,19) InChI=1S/C27H25N3O3/c1-2-19-9-6-10-23(15-19)30-17-22(16-25(30)31)27-28-26(29-33-27)21-11-13-24(14-12-21)32-18-20-7-4-3-5-8-20/h3-15,22H,2,16-18H2,1H3 InChI=1S/C7H13ClO3/c1-5(2)11-7(10)3-6(9)4-8/h5-6,9H,3-4H2,1-2H3/t6-/m0/s1 InChI=1S/C21H31N5O3S/c1-16(2)13-22-19(27)14-24-8-10-25(11-9-24)15-26-21(30)29-20(23-26)12-17-4-6-18(28-3)7-5-17/h4-7,16H,8-15H2,1-3H3,(H,22,27) InChI=1S/C17H16FN5O/c1-23-10-9-21-16(23)14(11-5-2-3-7-13(11)18)22-17(24)12-6-4-8-20-15(12)19/h2-10,14H,1H3,(H2,19,20)(H,22,24) InChI=1S/C24H54N2O3Si/c1-5-9-10-11-12-13-14-15-16-17-18-20-25-22-23-26-21-19-24-30(27-6-2,28-7-3)29-8-4/h25-26H,5-24H2,1-4H3 InChI=1S/C28H31N5O3/c1-35-25-11-10-23(18-26(25)36-2)30-27(34)21-12-16-31(17-13-21)20-22-19-29-33(24-8-4-3-5-9-24)28(22)32-14-6-7-15-32/h3-11,14-15,18-19,21H,12-13,16-17,20H2,1-2H3,(H,30,34) InChI=1S/C22H18F2N4O2/c23-22(24)9-11-28(21(29)18-12-17-16(26-18)6-3-10-25-17)13-19(22)30-20-8-7-14-4-1-2-5-15(14)27-20/h1-8,10,12,19,26H,9,11,13H2 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C28H28N2O4S/c1-5-33-27(31)23-17(3)29-18(4)24(28(32)34-6-2)25(23)20-14-10-11-15-21(20)26-30-22(16-35-26)19-12-8-7-9-13-19/h7-16,25,29H,5-6H2,1-4H3 InChI=1S/C36H39F4N3O3S2/c1-4-6-26-21-30(15-16-32(26)46-24(3)35(44)45-5-2)47-23-33-31(41-34(48-33)25-7-9-27(10-8-25)36(38,39)40)22-42-17-19-43(20-18-42)29-13-11-28(37)12-14-29/h7-16,21,24H,4-6,17-20,22-23H2,1-3H3 InChI=1S/C24H22FN7O/c1-13-10-16(18(25)11-19(13)33)22-17(12-26)20(21-23(27)30-31-24(21)29-22)14-2-4-15(5-3-14)32-8-6-28-7-9-32/h2-5,10-11,28,33H,6-9H2,1H3,(H3,27,29,30,31) InChI=1S/C5H18O2P2Si2/c1-6-11(5,9-8)7-10(2,3)4/h9H,8H2,1-5H3 InChI=1S/C16H15N5O3/c22-12-7-16(15(24)19-12)5-6-21(8-16)14(23)11-3-1-10(2-4-11)13-17-9-18-20-13/h1-4,9H,5-8H2,(H,17,18,20)(H,19,22,24)/t16-/m0/s1 InChI=1S/C17H18Cl2N2O4S/c18-15-4-3-12(10-16(15)19)20-17(22)21-7-5-14(6-8-21)26(23,24)11-13-2-1-9-25-13/h1-4,9-10,14H,5-8,11H2,(H,20,22) InChI=1S/C13H18N2O5S/c1-4-10(13(17)18)15-12(16)9-5-7(2)8(3)11(6-9)21(14,19)20/h5-6,10H,4H2,1-3H3,(H,15,16)(H,17,18)(H2,14,19,20) InChI=1S/C23H32N4O5S2/c1-17(22(28)31-2)33-23-25-24-21(27(23)19-9-5-3-4-6-10-19)18-8-7-11-20(16-18)34(29,30)26-12-14-32-15-13-26/h7-8,11,16-17,19H,3-6,9-10,12-15H2,1-2H3/t17-/m1/s1 InChI=1S/C17H17BrClN/c18-15-6-3-5-12(8-15)14-9-16(10-14)20-11-13-4-1-2-7-17(13)19/h1-8,14,16,20H,9-11H2 InChI=1S/C18H31NO/c1-5-9-15(4)13-18(19-7-3)16-10-8-11-17(14-16)20-12-6-2/h8,10-11,14-15,18-19H,5-7,9,12-13H2,1-4H3
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--&gt; 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in &lt;lambda&gt;(fig)
    248 
    249     if 'png' in formats:
--&gt; 250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
    252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--&gt; 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-&gt; 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

/opt/conda/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-&gt; 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--&gt; 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    399     def draw(self):
    400         # docstring inherited
--&gt; 401         self.renderer = self.get_renderer(cleared=True)
    402         # Acquire a lock on the shared font cache.
    403         with RendererAgg.lock, \

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    415                           and getattr(self, "_lastKey", None) == key)
    416         if not reuse_renderer:
--&gt; 417             self.renderer = RendererAgg(w, h, self.figure.dpi)
    418             self._lastKey = key
    419         elif cleared:

/opt/conda/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     89         self.width = width
     90         self.height = height
---&gt; 91         self._renderer = _RendererAgg(int(width), int(height), dpi)
     92         self._filter_renderers = []
     93 

ValueError: Image size of 70653x302 pixels is too large. It must be less than 2^16 in each direction.

&lt;Figure size 360x360 with 1 Axes&gt;
(224, 224) InChI=1S/C20H15FN2O5/c1-26-18-11-13(8-9-16(18)28-20(25)17-7-4-10-27-17)12-22-23-19(24)14-5-2-3-6-15(14)21/h2-12H,1H3,(H,23,24)/b22-12- InChI=1S/C14H18N2O4S/c1-4-12-9(2)7-11(14(18)16(12)3)13(17)15-10-5-6-21(19,20)8-10/h5-7,10H,4,8H2,1-3H3,(H,15,17)/t10-/m0/s1 InChI=1S/C18H31NO/c1-5-9-15(4)13-18(19-7-3)16-10-8-11-17(14-16)20-12-6-2/h8,10-11,14-15,18-19H,5-7,9,12-13H2,1-4H3 InChI=1S/C31H40FNO4/c1-30-16-13-23(34)19-21(30)5-8-24-25-9-10-27(31(25,2)17-14-26(24)30)37-29(36)12-11-28(35)33-18-15-20-3-6-22(32)7-4-20/h3-4,6-7,19,24-27H,5,8-18H2,1-2H3,(H,33,35) InChI=1S/C21H24F2N2O/c1-24(21(26)14-16-9-10-18(22)19(23)13-16)15-20(25-11-5-6-12-25)17-7-3-2-4-8-17/h2-4,7-10,13,20H,5-6,11-12,14-15H2,1H3 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C23H15F2NO3/c24-18-8-4-15(5-9-18)14-28-20-3-1-2-16(12-20)13-21-23(27)29-22(26-21)17-6-10-19(25)11-7-17/h1-13H,14H2 InChI=1S/C15H21FN2O2/c1-18(15(19)11-2-5-13(17)10-11)8-9-20-14-6-3-12(16)4-7-14/h3-4,6-7,11,13H,2,5,8-10,17H2,1H3 InChI=1S/C25H32N6O/c1-25(2,3)22-11-23-26-13-19-20-9-6-17(10-21(19)31(23)29-22)30(20)14-16-12-27-28-24(16)15-4-7-18(32)8-5-15/h4-5,7-8,11,13,16-17,20,24,27-28,32H,6,9-10,12,14H2,1-3H3 InChI=1S/C21H24N4O7/c1-3-31-15-9-13(14(10-16(15)32-4-2)25-19(26)21(29)30)17(20(27)28)24-12-7-5-11(6-8-12)18(22)23/h5-10,17,24H,3-4H2,1-2H3,(H3,22,23)(H,25,26)(H,27,28)(H,29,30) InChI=1S/C15H25NO3/c1-11-4-2-3-9-16(10-11)14(17)12-5-7-13(8-6-12)15(18)19/h11-13H,2-10H2,1H3,(H,18,19) InChI=1S/C15H25NO3/c1-11-4-2-3-9-16(10-11)14(17)12-5-7-13(8-6-12)15(18)19/h11-13H,2-10H2,1H3,(H,18,19) InChI=1S/C18H17NO2/c1-3-21-18-7-5-4-6-15(18)16-10-14-9-8-13(2)11-19(14)17(16)12-20/h4-12H,3H2,1-2H3 InChI=1S/C18H25N3/c1-12-8-14(3)15(9-13(12)2)10-19-17-6-5-7-18-16(17)11-20-21(18)4/h8-9,11,17,19H,5-7,10H2,1-4H3 InChI=1S/C21H24F3N3O3S/c1-14-5-11-18(12-6-14)31(29,30)26-13-15(2)27(20(28)21(22,23)24)19(26)16-7-9-17(10-8-16)25(3)4/h5-12,15,19H,13H2,1-4H3 InChI=1S/C25H32N6O/c1-25(2,3)22-11-23-26-13-19-20-9-6-17(10-21(19)31(23)29-22)30(20)14-16-12-27-28-24(16)15-4-7-18(32)8-5-15/h4-5,7-8,11,13,16-17,20,24,27-28,32H,6,9-10,12,14H2,1-3H3 InChI=1S/C13H16N2O3S/c1-5-18-12(17)9-14-10(16)8-7(13(2,3)4)6-19-11(8)15-9/h6H,5H2,1-4H3,(H,14,15,16) InChI=1S/C12H20N4O/c1-9(2)8-14-12(17)6-7-13-11-5-4-10(3)15-16-11/h4-5,9H,6-8H2,1-3H3,(H,13,16)(H,14,17) InChI=1S/C10H9FN2OS/c11-7-1-2-9-6(3-7)4-8(15-9)5-10(12)13-14/h1-4,14H,5H2,(H2,12,13) InChI=1S/C12H21N3O3/c1-12(2,3)15-11(16)9(6-13)7-14-8-10(17-4)18-5/h7,10,14H,8H2,1-5H3,(H,15,16)/b9-7- InChI=1S/C15H21NO2/c1-4-16(13-9-10-13)15(3,14(17)18)12-7-5-11(2)6-8-12/h5-8,13H,4,9-10H2,1-3H3,(H,17,18) InChI=1S/C24H54N2O3Si/c1-5-9-10-11-12-13-14-15-16-17-18-20-25-22-23-26-21-19-24-30(27-6-2,28-7-3)29-8-4/h25-26H,5-24H2,1-4H3 InChI=1S/C28H31N5O3/c1-35-25-11-10-23(18-26(25)36-2)30-27(34)21-12-16-31(17-13-21)20-22-19-29-33(24-8-4-3-5-9-24)28(22)32-14-6-7-15-32/h3-11,14-15,18-19,21H,12-13,16-17,20H2,1-2H3,(H,30,34) InChI=1S/C22H18F2N4O2/c23-22(24)9-11-28(21(29)18-12-17-16(26-18)6-3-10-25-17)13-19(22)30-20-8-7-14-4-1-2-5-15(14)27-20/h1-8,10,12,19,26H,9,11,13H2 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C28H28N2O4S/c1-5-33-27(31)23-17(3)29-18(4)24(28(32)34-6-2)25(23)20-14-10-11-15-21(20)26-30-22(16-35-26)19-12-8-7-9-13-19/h7-16,25,29H,5-6H2,1-4H3 InChI=1S/C36H39F4N3O3S2/c1-4-6-26-21-30(15-16-32(26)46-24(3)35(44)45-5-2)47-23-33-31(41-34(48-33)25-7-9-27(10-8-25)36(38,39)40)22-42-17-19-43(20-18-42)29-13-11-28(37)12-14-29/h7-16,21,24H,4-6,17-20,22-23H2,1-3H3 InChI=1S/C10H15Cl2N3O2/c1-16-10-14-7-8(12)9(15-10)13-4-2-5-17-6-3-11/h7H,2-6H2,1H3,(H,13,14,15) InChI=1S/C19H28O/c1-4-6-7-8-9-13-16-20-19(17(3)5-2)18-14-11-10-12-15-18/h10-12,14-15,19H,2,4,6-9,13,16H2,1,3H3 InChI=1S/C17H24N2O2/c1-18-16(21)13-15(14-5-3-2-4-6-14)17(18)7-9-19(10-8-17)11-12-20/h2-6,15,20H,7-13H2,1H3/t15-/m1/s1 InChI=1S/C19H19NO4S/c1-11(2)23-15-7-6-13(10-16(15)22-4)9-14-19(21)24-18(20-14)17-8-5-12(3)25-17/h5-11H,1-4H3/b14-9- InChI=1S/C20H24N2O2/c1-15-4-6-17(7-5-15)22-11-12-23-20-18(22)8-9-19(20)24-14-16-3-2-10-21-13-16/h2-7,10,13,18-20H,8-9,11-12,14H2,1H3/t18-,19-,20+/m0/s1 InChI=1S/C18H26FN3O2/c19-17-7-2-1-5-15(17)13-20-18(23)22-9-4-8-21(10-11-22)14-16-6-3-12-24-16/h1-2,5,7,16H,3-4,6,8-14H2,(H,20,23) InChI=1S/C18H34O5/c1-2-3-4-5-6-7-8-9-10-11-12-22-18-16(21)14-23-17(18)15(20)13-19/h7-8,15-21H,2-6,9-14H2,1H3/b8-7+/t15-,16+,17+,18+/m0/s1 InChI=1S/C14H18N4O/c1-10-8-13(18(2)17-10)16-14(19)9-12(15)11-6-4-3-5-7-11/h3-8,12H,9,15H2,1-2H3,(H,16,19) InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C21H21N5O2S/c1-15-7-8-18(17-5-4-11-22-20(15)17)29(27,28)25-13-9-16(10-14-25)21-24-23-19-6-2-3-12-26(19)21/h2-8,11-12,16H,9-10,13-14H2,1H3 InChI=1S/C11H22N2O3/c1-10(2,3-4-14)6-13-11(5-9(15)16)7-12-8-11/h12-14H,3-8H2,1-2H3,(H,15,16) InChI=1S/C17H21N3O5S/c1-10(2)9-25-16(23)14-11(3)18-17(26-14)19-13(21)8-20-7-5-6-12(24-4)15(20)22/h5-7,10H,8-9H2,1-4H3,(H,18,19,21) InChI=1S/C17H21N3O5S/c1-10(2)9-25-16(23)14-11(3)18-17(26-14)19-13(21)8-20-7-5-6-12(24-4)15(20)22/h5-7,10H,8-9H2,1-4H3,(H,18,19,21) InChI=1S/C31H32N6O4S/c1-20(2)19-41-29(38)18-37(42(39,40)27-8-4-6-22-7-5-15-34-30(22)27)24-13-14-26-25(17-24)35-28(36(26)3)16-21-9-11-23(12-10-21)31(32)33/h4-15,17,20H,16,18-19H2,1-3H3,(H3,32,33) InChI=1S/C20H24N2O2/c1-15-4-6-17(7-5-15)22-11-12-23-20-18(22)8-9-19(20)24-14-16-3-2-10-21-13-16/h2-7,10,13,18-20H,8-9,11-12,14H2,1H3/t18-,19-,20+/m0/s1 InChI=1S/C17H18BrClFNO2/c1-11(22)8-21-9-13-6-14(18)3-5-17(13)23-10-12-2-4-15(20)7-16(12)19/h2-7,11,21-22H,8-10H2,1H3/t11-/m0/s1 InChI=1S/C48H96N4O5/c1-4-7-10-13-16-25-32-42-56-47(54)36-28-21-17-23-30-38-51(40-33-41-52(50)43-45(49)44-53)39-31-24-18-22-29-37-48(55)57-46(34-26-19-14-11-8-5-2)35-27-20-15-12-9-6-3/h43,46,53H,4-42,44,49-50H2,1-3H3/b45-43- InChI=1S/C18H30N2O3/c1-2-23-18(22)16-9-12-20(13-10-16)14-17(21)19-11-8-15-6-4-3-5-7-15/h6,16H,2-5,7-14H2,1H3,(H,19,21) InChI=1S/C22H25NO5S/c1-29(26,27)20-14-12-17(13-15-20)22(25)28-16-21(24)23(18-8-4-2-5-9-18)19-10-6-3-7-11-19/h2,4-5,8-9,12-15,19H,3,6-7,10-11,16H2,1H3 InChI=1S/C31H35F2N5O3/c1-19-27(26-22(33)12-20(32)13-23(26)35-29(19)38-17-30(2,3)15-25(38)39)37-18-31(4-8-40-9-5-31)28-24(37)14-21(16-34-28)36-6-10-41-11-7-36/h12-14,16H,4-11,15,17-18H2,1-3H3 InChI=1S/C31H35F2N5O3/c1-19-27(26-22(33)12-20(32)13-23(26)35-29(19)38-17-30(2,3)15-25(38)39)37-18-31(4-8-40-9-5-31)28-24(37)14-21(16-34-28)36-6-10-41-11-7-36/h12-14,16H,4-11,15,17-18H2,1-3H3 InChI=1S/C18H22N6O/c1-13(11-24-15(3)8-14(2)22-24)9-21-18(25)16-4-5-17(20-10-16)23-7-6-19-12-23/h4-8,10,12-13H,9,11H2,1-3H3,(H,21,25)/t13-/m0/s1 InChI=1S/C24H28ClN3O3/c1-17-5-7-18(8-6-17)22(27-9-11-31-12-10-27)15-26-24(30)19-13-23(29)28(16-19)21-4-2-3-20(25)14-21/h2-8,14,19,22H,9-13,15-16H2,1H3,(H,26,30) InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C21H31N5O3S/c1-16(2)13-22-19(27)14-24-8-10-25(11-9-24)15-26-21(30)29-20(23-26)12-17-4-6-18(28-3)7-5-17/h4-7,16H,8-15H2,1-3H3,(H,22,27) InChI=1S/C13H19NO4S/c1-4-10(2)14-13(15)9-18-11-5-7-12(8-6-11)19(3,16)17/h5-8,10H,4,9H2,1-3H3,(H,14,15) InChI=1S/C24H30ClN3O2/c1-3-18(4-2)24(29)26-15-14-23-27-20-11-6-7-12-21(20)28(23)16-9-17-30-22-13-8-5-10-19(22)25/h5-8,10-13,18H,3-4,9,14-17H2,1-2H3,(H,26,29) InChI=1S/C31H29F2N3O/c1-2-3-9-28-35-31(16-4-5-17-31)30(37)36(28)20-21-10-12-22(13-11-21)26-18-23(14-15-24(26)19-34)25-7-6-8-27(32)29(25)33/h6-8,10-15,18H,2-5,9,16-17,20H2,1H3 InChI=1S/C12H12O3S/c1-15-12(14)7-6-11(13)10-4-2-9(8-16)3-5-10/h2-5,8H,6-7H2,1H3 InChI=1S/C21H20ClFN4O7S/c1-26(31)17(10-11-27-19(28)12-18(22)24-21(27)30)20(29)25-35(32,33)16-8-6-15(7-9-16)34-14-4-2-13(23)3-5-14/h2-9,12,17,31H,10-11H2,1H3,(H,24,30)(H,25,29)/t17-/m0/s1 InChI=1S/C11H19N3O/c1-7(2)9(12)11-13-10(14-15-11)8-5-3-4-6-8/h7-9H,3-6,12H2,1-2H3/t9-/m0/s1 InChI=1S/C14H18N2O3/c1-9(6-13(17)18)16-14(19)15-8-11-7-10-4-2-3-5-12(10)11/h2-5,9,11H,6-8H2,1H3,(H,17,18)(H2,15,16,19) InChI=1S/C27H25N3O3/c1-2-19-9-6-10-23(15-19)30-17-22(16-25(30)31)27-28-26(29-33-27)21-11-13-24(14-12-21)32-18-20-7-4-3-5-8-20/h3-15,22H,2,16-18H2,1H3 InChI=1S/C7H13ClO3/c1-5(2)11-7(10)3-6(9)4-8/h5-6,9H,3-4H2,1-2H3/t6-/m0/s1 InChI=1S/C21H31N5O3S/c1-16(2)13-22-19(27)14-24-8-10-25(11-9-24)15-26-21(30)29-20(23-26)12-17-4-6-18(28-3)7-5-17/h4-7,16H,8-15H2,1-3H3,(H,22,27) InChI=1S/C17H16FN5O/c1-23-10-9-21-16(23)14(11-5-2-3-7-13(11)18)22-17(24)12-6-4-8-20-15(12)19/h2-10,14H,1H3,(H2,19,20)(H,22,24) InChI=1S/C24H54N2O3Si/c1-5-9-10-11-12-13-14-15-16-17-18-20-25-22-23-26-21-19-24-30(27-6-2,28-7-3)29-8-4/h25-26H,5-24H2,1-4H3 InChI=1S/C28H31N5O3/c1-35-25-11-10-23(18-26(25)36-2)30-27(34)21-12-16-31(17-13-21)20-22-19-29-33(24-8-4-3-5-9-24)28(22)32-14-6-7-15-32/h3-11,14-15,18-19,21H,12-13,16-17,20H2,1-2H3,(H,30,34) InChI=1S/C22H18F2N4O2/c23-22(24)9-11-28(21(29)18-12-17-16(26-18)6-3-10-25-17)13-19(22)30-20-8-7-14-4-1-2-5-15(14)27-20/h1-8,10,12,19,26H,9,11,13H2 InChI=1S/C18H19Cl2NO2/c1-12(2)9-10-23-14-6-3-5-13(11-14)18(22)21-17-15(19)7-4-8-16(17)20/h3-8,11-12H,9-10H2,1-2H3,(H,21,22) InChI=1S/C14H19F4NO/c1-4-7-19-9-13(2,3)20-10-5-6-12(15)11(8-10)14(16,17)18/h5-6,8,19H,4,7,9H2,1-3H3 InChI=1S/C28H28N2O4S/c1-5-33-27(31)23-17(3)29-18(4)24(28(32)34-6-2)25(23)20-14-10-11-15-21(20)26-30-22(16-35-26)19-12-8-7-9-13-19/h7-16,25,29H,5-6H2,1-4H3 InChI=1S/C36H39F4N3O3S2/c1-4-6-26-21-30(15-16-32(26)46-24(3)35(44)45-5-2)47-23-33-31(41-34(48-33)25-7-9-27(10-8-25)36(38,39)40)22-42-17-19-43(20-18-42)29-13-11-28(37)12-14-29/h7-16,21,24H,4-6,17-20,22-23H2,1-3H3 InChI=1S/C24H22FN7O/c1-13-10-16(18(25)11-19(13)33)22-17(12-26)20(21-23(27)30-31-24(21)29-22)14-2-4-15(5-3-14)32-8-6-28-7-9-32/h2-5,10-11,28,33H,6-9H2,1H3,(H3,27,29,30,31) InChI=1S/C5H18O2P2Si2/c1-6-11(5,9-8)7-10(2,3)4/h9H,8H2,1-5H3 InChI=1S/C16H15N5O3/c22-12-7-16(15(24)19-12)5-6-21(8-16)14(23)11-3-1-10(2-4-11)13-17-9-18-20-13/h1-4,9H,5-8H2,(H,17,18,20)(H,19,22,24)/t16-/m0/s1 InChI=1S/C17H18Cl2N2O4S/c18-15-4-3-12(10-16(15)19)20-17(22)21-7-5-14(6-8-21)26(23,24)11-13-2-1-9-25-13/h1-4,9-10,14H,5-8,11H2,(H,20,22) InChI=1S/C13H18N2O5S/c1-4-10(13(17)18)15-12(16)9-5-7(2)8(3)11(6-9)21(14,19)20/h5-6,10H,4H2,1-3H3,(H,15,16)(H,17,18)(H2,14,19,20) InChI=1S/C23H32N4O5S2/c1-17(22(28)31-2)33-23-25-24-21(27(23)19-9-5-3-4-6-10-19)18-8-7-11-20(16-18)34(29,30)26-12-14-32-15-13-26/h7-8,11,16-17,19H,3-6,9-10,12-15H2,1-2H3/t17-/m1/s1 InChI=1S/C17H17BrClN/c18-15-6-3-5-12(8-15)14-9-16(10-14)20-11-13-4-1-2-7-17(13)19/h1-8,14,16,20H,9-11H2 InChI=1S/C18H31NO/c1-5-9-15(4)13-18(19-7-3)16-10-8-11-17(14-16)20-12-6-2/h8,10-11,14-15,18-19H,5-7,9,12-13H2,1-4H3
</code></pre>
<p>Is there a way to remove the caption/sentence before showing the image?  At the end of the pipeline I really just need a caption/sentence for every image, so it’s not absolutely necessary to show the image.</p>

username: Epoching
cooked: <p>Hmmm if you don’t want to use a caption at all, you can use jupyter’s <code>display</code> function!</p>
<p>i.e.</p>
<p><code>display(org_image)</code> <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p>If you still want to use the caption, I’d just trim it first:</p>
<p>i.e.</p>
<p><code>sentence = sentence[:100]</code> or some other slice!</p>

username: Jennifer_Davis
cooked: <p>Ah, great.  But really I just need the image label, and the caption.  I don’t need to show the image.  So maybe extract the data with something using part of this?</p>
<pre><code class="lang-auto">train_features, labels, captions = next(iter(trn_dl))

print(train_features, labels, captions)
</code></pre>
<p>Where I make a dataframe that just has the labels and captions.</p>

username: Epoching
cooked: <p>Yea that could work! add a particular column for label/caption prediction to the dataframe!</p>

username: Jennifer_Davis
cooked: <p>Great, thank you so much!</p>