AssertionError while fine_tune()

Hey guys, I’m just starting here and with DL. I’m building image multi-label-classifier, but while fine_tune(10), I receive following error after first epoch: "

AssertionError: Exception occured in `Recorder` when calling event `after_batch`:
	==: "

My code:

training = tuple(zip(train_X, train_y)) # where train_X is a 3rd rank tensor in a shape of (300,256,256), and train_y is tensor shaped (300,)

epl_2122_season = DataBlock(
    blocks=(ImageBlock(), MultiCategoryBlock()),
    get_x=ItemGetter(0), get_y=ItemGetter(1))

dls = epl_2122_season.dataloaders(
    source=training, shuffle=False)
learn = vision_learner(dls, resnet18, metrics=accuracy)
learn.fine_tune(10)

Below I also paste a summary(training) output.


Found 300 items
2 datasets of sizes 240,60
Setting up Pipeline: ItemGetter -> PILBase.create
Setting up Pipeline: ItemGetter -> MultiCategorize -- {'vocab': None, 'sort': True, 'add_na': False} -> OneHotEncode -- {'c': None}
Setting up after_item: Pipeline: ToTensor
Setting up before_batch: Pipeline: 
Setting up after_batch: Pipeline: IntToFloatTensor -- {'div': 255.0, 'div_mask': 1}

Building one batch
Applying item_tfms to the first sample:
  Pipeline: ToTensor
    starting from
      (PILImage mode=F size=258x258, TensorMultiCategory([1., 0., 0.]))
    applying ToTensor gives
      (TensorImage of size 1x258x258, TensorMultiCategory([1., 0., 0.]))

Adding the next 3 samples

No before_batch transform to apply

Collating items in a batch

Applying batch_tfms to the batch built
  Pipeline: IntToFloatTensor -- {'div': 255.0, 'div_mask': 1}
    starting from
      (TensorImage of size 4x1x258x258, TensorMultiCategory of size 4x3)
    applying IntToFloatTensor -- {'div': 255.0, 'div_mask': 1} gives
      (TensorImage of size 4x1x258x258, TensorMultiCategory of size 4x3)

Any ideas why I’m getting this error?

1 Like

Hello,

You mention you are developing a multi-label classifier, but train_y is a vector of dimension 300, which leads me to believe there is only one class per input, i.e., it is multi-class classification. Is there anything I am missing? Nevertheless, the issue that produces the AssertionError is likely unrelated and arises from the usage of accuracy as a metric. Since the application is multi-label classification, it should be replaced with accuracy_multi. Again though, I don’t see how train_y, a rank-one tensor, is being used as the target variable for a multi-label task, so I might be mistaken.

Does that solve your issue?

2 Likes

Hey, sorry for the late response, I was ill. Yes, you were right. That was the main problem. Thank You!

1 Like