The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

154463 (2) [Avatar] Offline
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 (16) [Avatar] Offline
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:

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).

Eli Stevens (16) [Avatar] Offline
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

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