dsgiitr / d2l-pytorch

This project reproduces the book Dive Into Deep Learning (https://d2l.ai/), adapting the code from MXNet into PyTorch.
Apache License 2.0
4.24k stars 1.24k forks source link

code clarification in Ch09_Modern_Convolutional_Networks Residual_Networks_(ResNet) #124

Closed IANGECHUKI176 closed 1 year ago

IANGECHUKI176 commented 1 year ago

This is the original code

def resnet_block(input_channels, num_channels, num_residuals, first_block=False):
  blk = []
  for i in range(num_residuals):
    if i == 0 and not first_block:
      blk.append(Residual(input_channels, num_channels, use_1x1conv=True, strides=2))
    else:
      blk.append(Residual(num_channels, num_channels))
  return blk

I tried running the code in colab but there was a channel error. so I added the last line of code

in_channels = out_channels

And the new code looks like this .and it runs ok.

def resnet_block(in_channels,out_channels,num_residuals,first_block = False):
    blk = []
    for i in range(num_residuals):
        if i == 0 or not first_block:
            blk.append(Residual(in_channels,out_channels,use_1x1conv= True,strides = 2))
        else:
            blk.append(Residual(out_channels,out_channels))
        in_channels = out_channels
    return blk
AnirudhDagar commented 1 year ago

Hi! We no longer maintain this repo. Please check out https://github.com/d2l-ai/d2l-en for the latest up to date code.