Unable to understand DataBunch code from Lesson 5

(Vishak Bharadwaj S) #1

Hey Guys

I was having a look at the create() method in the DataBunch Class

A lot of things didn’t make sense to me though.

The first line is

datasets = cls._init_ds(train_ds, valid_ds, test_ds)

The definition of _Init_ds is right above the codeblock for DataBunch but I have no idea what it is doing at the level of code

The second line uses ifnone and I can’t find what that is

and the last two lines, well…
dls = [DataLoader(d, b, shuffle=s, drop_last=s, num_workers=num_workers, **dl_kwargs) for d,b,s in zip(datasets, (bs,val_bs,val_bs,val_bs), (True,False,False,False)) if d is not None]
return cls(*dls, path=path, device=device, dl_tfms=dl_tfms, collate_fn=collate_fn, no_check=no_check)

Any help would be highly appreciated

0 Likes

(Elena) #2

Hey, just as a quick hint: maybe the docs can help you answer some of your questions! I was a bit lost with all that code in the beginning as well but by navigating through the code and the docs AND testing/programming several things myself I learned a lot of how things are done in fastai :slight_smile:

1 Like

(Vishak Bharadwaj S) #3

Hey, sorry for the late reply.

I’m going through the docs, but sometimes they’ve done things with the code that don’t really make it to the docs, so stuff like this is a little confusing

0 Likes