Labeling images with float embedded in filename

Hi, I am having issues properly labeling images in an ImageDataBunch. I’ve explicitly defined the label as a FloatList, but it still keeps trying to label it using a CategoryList. I’ve verified that the regular expression does properly pull the float from the filename. Does anyone have any idea what I’m missing or doing wrong?

Example file names:

cryptopics/2017-09-22 00:00:00_1.0221594864258645.png
cryptopics/2013-11-26 00:00:00_1.1614170764976035.png
cryptopics/2017-09-26 00:00:00_0.9832723292169808.png

Code:

path = "cryptopics/"
fnames = get_image_files(path)
reg = r'(?!_)(.\.[^\.]*)'
data = (ImageDataBunch.from_name_re(path=path, fnames=fnames, pat=reg, size=24, label_cls= FloatList)
                                   .split_by_rand_pct(seed=42)
                                   .databunch())

Error:

/home/luke/Documents/pythonscripts/fastai/venv/lib/python3.6/site-packages/fastai/data_block.py:541: UserWarning: You are labelling your items with CategoryList.
Your valid set contained the following unknown labels, the corresponding items have been discarded.
0.980382398075567, 0.9753673292999135, 0.9847830967645371, 1.0117103822535345, 1.0020466865803739...
  if getattr(ds, 'warn', False): warn(ds.warn)

I researched this for hours, but of course fixed it a few minutes after posting. I changed the ImageDataBunch to an ImageList. Below is the code that got it to start working.

reg = r'(?!_)(.\.[^\.]*)'
data = (ImageList.from_folder(path)
            .split_by_rand_pct(seed=42)
            .label_from_re(reg, label_cls=FloatList)
            .databunch(bs=20))

learn = cnn_learner(data, models.resnet18)
learn.fit_one_cycle(4)
1 Like