154463 (2) [Avatar] Offline
#1
Can you clarify the code block on the bottom of page 103 in Version 5 of the MEAP that reads:

batch_size = 100
batch = torch.ByteTensor(100, 3, 256, 256)

data_dir = 'ch3/data/cats/'
filenames = [name for name in os.listdir(data_dir) if os.split_ext(name) == '.png']
for i, filename in enumerate(filenames):
    img_arr = imageio.imread(filename)
    batch[i] = torch.transpose(torch.from_numpy(img_arr), 0, 2)


I don't believe this is actually batching the images because as written it throws an IndexError as it iterates the files. I also believe the code at the top of the page isn't actually producing a C x H x W, but a C x W x H tensor. I used .permute instead, but perhaps I am misreading it. Thank you.
Eli Stevens (10) [Avatar] Online
#2
Hi, you have good timing. I've just finished up moving the first four chapters' code over to Jupyter Notebooks, along with fixing issues like what you describe. The new files are up on GitHub as of a few minutes ago; the one you mention specifically is here:

https://github.com/deep-learning-with-pytorch/bookcode/blob/master/p1ch4/5_image_dog.ipynb

The chapter 4 code specifically is broken up into multiple files, but it should be pretty easy to figure out which one applies to each section.

Unfortunately, this doesn't include the updated book text (which has a correction for the error you noted about the tensor dimensions); for that we'll have to wait for the next MEAP update. I'm not sure what the schedule for that will be, but I'd imagine in the next few weeks. Once that happens, the code in the notebooks and the code in the book PDFs should be in sync (and stay in sync should there be further changes made).

Hope this helps! As always, please let us know if you have any feedback (good or bad -- they're both useful when working on the book).

Cheers,
Eli
Eli Stevens (10) [Avatar] Online
#3
I should also note that despite the (now outdated) text in the book, all of my code examples were tested against PyTorch v1.0.
154463 (2) [Avatar] Offline
#4
Eli,

Thanks for the update. I'll get the latest from the repo. Keep up the good work!