Borun Chowdhury
Borun Chowdhury

Reputation: 531

FastAi Learner changes the dataloader Why do they do it? How is this the right thing to do?

The code below shows that passing a dataloader to a learner changes it. This seems like a very odd behavior. Why is it done this way, what is the logic for the change and how can I turn it off?

More importantly, the dataloader also has the val and test data in it. If the learner goes around changing it then it should be very well documented on what its doing. Nothing is mentioned about changing the data loader in cnn_learner and Learner.

dls = ImageDataLoaders.from_name_func(path, get_image_files(path), valid_pct=0.2,
label_func=is_tb,item_tfms=Resize(224))


x,y=next(iter(dls[0]))
print(x.min(),x.max())

This gives 0 and 1 respectively. However, initiating a learner


learn = cnn_learner(dls, resnet34, metrics=[accuracy],n_out=2,loss_func=CrossEntropyLossFlat())

x,y=next(iter(dls[0]))
print(x.min(),x.max())

I get -2.11 and 2.64 respectively.

Upvotes: 0

Views: 260

Answers (1)

Ivan
Ivan

Reputation: 40648

The ImageDataLoaders.from_name_func dataloader shuffles the dataset by default.

You can pass it shuffle_train=False if you don't want to.

Upvotes: 1

Related Questions