ImageClassifierData.from_csv gives IndexError: tuple index out of range

Hello, I am trying to do the dog breed identification challenge and when I try to run this code, it gives me this error, I’m not sure if it’s something I’m doing or the fastai library itself:

It’s also important to note that this suddenly started to happen. The first time I tried to run this I faced no problems!

can you print the inputs you used to create the ImageClassifierData?
Particularly interested on val_idxs

Here you go:

Also the value of val_idxs is:

array([2882, 4514, 7717, ..., 8922, 6774, 37])

i wonder whether this pull request 2 days ago has broke it:
https://github.com/fastai/fastai/commit/2171271588749cc2a072fae397218936350d5dde#diff-59710560342913742b5e0faaaedd8aae

if you print out trn.shape and len(trn[1].shape) then maybe you see the cause. I supect that len(trn[1].shape)=1, and causes this error.

2 Likes

I actually replaced trn[1].shape[1] with 1 and it works fine now. Not sure why though :confused:

1 Like

to be honest, I can’t figure out why ‘trn[1].shape[1]’ is there… I quess there should be additional if:
if len(trn[1].shape==1): 1
else: len(trn[1].shape[1]

reason could be that we are trying to initialize second dimension (width) to labels. So, if there are more than one label, eg.multilabel classification then len(trn[1].shape[1]) > 1. That is my interpretation of this code. As always I could be mistaken again :slight_smile:

1 Like

Thank you so much!

same problem here… and workaround worked for me. thanks @deruhat @urmas.pitsi

3 Likes

That could be because of latest updated in fasta.ai . My code was working fine until yesterday that I updated my fork from the latest version of the upstream and now I see this error. A fix
est_lbls = np.zeros((len(test), trn[1].shape[1] if len(trn[1].shape) > 1 else 1))

I believe the PR merged today should fix this. Let me know if that’s not the case.

2 Likes

I had the same issue. I just issued a git pull and it works now. thank you