Warnings when trying to make an ImageDataBunch

I’m trying to make an ImageDataBunch from the training images collected here:

Which are different sizes and rotations and such. But when I run this:

label_pattern = r'/board\d+_(red|green|purple)-(diamond|oval|squiggle)-(empty|filled|hashed)-(single|double|triple).png$'
bunch = ImageDataBunch.from_name_re('.', imagefiles, label_pattern, ds_tfms=get_transforms(max_zoom=1, max_warp=None), size=224, bs=bs, resize_method=ResizeMethod.SQUISH).normalize(imagenet_stats)

I get a boat ton of warnings like:

/homedir/.local/share/virtualenvs/jupyter-5S1mKFjG/lib/python3.7/site-packages/torch/nn/functional.py:2693: UserWarning: Default grid_sample and affine_grid behavior will be changed to align_corners=False from 1.4.0. See the documentation of grid_sample for details.
  warnings.warn("Default grid_sample and affine_grid behavior will be changed "

What am I doing wrong?

3 Likes

It’s not your code, it’s a change in PyTorch 1.3.0 that fastai hasn’t been updated for yet.

3 Likes

As noted in the github issue for it you can suppress the message with:

import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="torch.nn.functional")
11 Likes

I’m running into the same problem and filtering this warning definitely cleans up the notebook, but I can’t tell if something else is going on too – I’m running into a weird problem with jupyter stalling on the creation of an ImageDataBunch in a notebook that previously worked fine (as of a few days ago).

My code is quite simple:

from fastai.vision import *
from fastai.metrics import error_rate
bs = 64 # batch size at 64
base_dir = "/pedfast-pv/code/experiment-1/annotated/DS1/"
labeled_images = get_image_files(base_dir + "labeled/") # hello helpful library!
labeled_images[:5]
np.random.seed(1010102)
pat = r'/([^/]+)_.*.png$'
data = ImageDataBunch.from_name_re(base_dir+"labeled/", labeled_images, pat, ds_tfms=get_transforms(), size=224, bs=bs
                                  ).normalize(imagenet_stats)

All of that runs pretty smoothly.

data.show_batch(rows=3, figsize=(7,6))

^^^ that line causes the notebook to stall, for a VERY long time and eventually finishes and it results in the symptom below:

The only symptom I can see is that ZMQbg/1 on the server running the notebook is pegged at nearly 100% CPU utilization and has a huge alleged allocation of memory:

Tasks:  24 total,   2 running,  22 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.4 us,  0.5 sy,  0.0 ni, 97.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 79123404+total, 70943737+free, 11638572 used, 70158128 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 77615289+avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 71070 root      20   0 12.143g 3.261g 427964 R 100.3  0.4   5:45.58 ZMQbg/1
 70999 root      20   0 9540924 1.091g 161880 S   1.7  0.1   0:38.47 ZMQbg/1
 69892 root      20   0  251244  79064  15800 S   1.3  0.0   0:12.80 ZMQbg/1
 15322 root      20   0   24748   4628   3276 S   1.0  0.0   2:35.44 htop```

Hey @djmax,
I’m not sure if you got this worked out, but I just got a similar issue and kinda “figured it out”.
I’m totally new in every sense of the word but thought maybe I share this.
While doing the lesson 1 on Colab, I got the error
colab warnings.warn("Default grid_sample and affine_grid behavior will be changed
while making the ImageDataBunch, my browser froze, and everything stopped. As stated by @TomB (Thank you), it seems related to the version of pytorch.
I solve it by !pip install -q torch==1.0.0 torchvision to downgrade the torch version. I don’t know if this is healthy, but everything worked fine afterwards.

The import warnings and running warning.filterwarning() worked for me.

Thank you so much sir, really appreciate your help. thank you.

Thanks!

This helped immensely… I was getting crazy over this error :slight_smile:

Thanks Tom, brilliant!