Can any one help please why do i get the error in subject
else self.items.__array__()[(i,)] if hasattr(self.items,'__array__')
--> 191 else [self.items[i_] for i_ in i])
192
IndexError: list index out of range
#add stratified k fold split.
def get_dls(sz,bs):
item_tfms = AlbumentationsTransform(get_train_aug(sz), get_valid_aug(sz))
batch_tfms = [Normalize.from_stats(*imagenet_stats)]
dls = ImageDataLoaders.from_df(train_df, #pass in train DataFrame
#valid_pct=0.2, #80-20 train-validation random split
#valid_col=1,
seed=42, #seed
label_col=0, #label is in the first column of the DataFrame
fn_col=2, #filename/path is in the second column of the DataFrame
bs=bs, #pass in batch size
item_tfms=item_tfms, #pass in item_tfms
batch_tfms=batch_tfms,val_idxs=val_idx) #pass in batch_tfms
return dls
This is source of error
class ProgressiveLabelCorrection(Callback):
'https://openreview.net/pdf?id=ZPa2SyGcbwh'
run_valid=False
def __init__(self, num_classes=5, theta_start=0.3, theta_end=0.05, warm_up=0.2, sched_func=sched_lin):
store_attr()
self.theta = theta_start
def before_fit(self):
self.eye = torch.eye(self.num_classes).to(self.dls.device)
def after_step(self):
if self.pct_train > self.warm_up:
# get batch items
self.idxs = self.dl._DataLoader__idxs
self.b_items = L(self.dl.items)[self.idxs[self.iter*self.dl.bs:
self.iter*self.dl.bs+self.dl.bs]]
# get incorrectly classified item boolean mask
preds_max = self.pred.argmax(-1)
mislabeled_idxs = preds_max != self.y
tot_mislabeled = sum(mislabeled_idxs)
if tot_mislabeled > 0:
# get probas and targs for incorrect batch items
mislabeled_probas = self.pred[mislabeled_idxs].softmax(-1)
mislabeled_targs = self.y[mislabeled_idxs]
# get predicted and actual probas and targ
predicted_probas = mislabeled_probas.max(-1).values
predicted_targs = mislabeled_probas.max(-1).indices
actual_probas = mislabeled_probas[self.eye[mislabeled_targs].bool()]
# update labels or theta
msk = torch.abs(predicted_probas - actual_probas) > self.theta
self.epoch_tot_updated += sum(msk)
new_targs = self.dl.tfms[1][1].vocab[predicted_targs[msk]]
items_to_change = self.b_items[mislabeled_idxs][msk]
update_dict = dict(zip(items_to_change, new_targs))
self.dl.tfms[1][0].fname2labels.update(update_dict)
def before_epoch(self): self.epoch_tot_updated = 0
def after_epoch(self):
print(f"Total changed items in this epoch: {self.epoch_tot_updated}")
if (self.pct_train > self.warm_up) and (self.epoch_tot_updated == 0):
self.theta = self.sched_func(self.theta_start, self.theta_end, self.pct_train)
print(f"Reduced theta to: {self.theta}")