oreilly-japan / deep-learning-from-scratch

『ゼロから作る Deep Learning』(O'Reilly Japan, 2016)
MIT License
3.99k stars 3.34k forks source link

deep_convnet.py #60

Open littleeboy opened 3 years ago

littleeboy commented 3 years ago

in deep_convnet.py pre_node_nums = np.array([1*3*3, 16*3*3, 16*3*3, 32*3*3, 32*3*3, 64*3*3, 64*4*4, hidden_size])

how to compute the neurons number in each convolution layer? why not pre_node_nums = np.array([1*3*3, 16, 16, 32, 32, 64, 64*4*4, hidden_size]

thanks

arandinglv commented 10 months ago

Hey bro, If I'm not wrong, I think the pre_node_num is decided by yours, no matter you what value you assign, the code can run successfully ang get a suitable result. However, it is noteworthy that the self.params['W7'] = wight_init_scales[6] * np.random.randn(64 * 4 * 4, hidden_size) should be paid more anttention to calculate, cus I spent a long time to find that how to calculate the final result. The result should folow the order of layer, and the feature map size will be changed accoding to the pooling and convolution layer:

    `self.layers = []
    self.layers.append(Convolution(self.params['W1'], self.params['b1'], 
                       conv_param_1['stride'], conv_param_1['pad']))
    self.layers.append(Relu())
    self.layers.append(Convolution(self.params['W2'], self.params['b2'], 
                       conv_param_2['stride'], conv_param_2['pad']))
    self.layers.append(Relu())
    self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
    self.layers.append(Convolution(self.params['W3'], self.params['b3'], 
                       conv_param_3['stride'], conv_param_3['pad']))
    self.layers.append(Relu())
    self.layers.append(Convolution(self.params['W4'], self.params['b4'],
                       conv_param_4['stride'], conv_param_4['pad']))
    self.layers.append(Relu())
    self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
    self.layers.append(Convolution(self.params['W5'], self.params['b5'],
                       conv_param_5['stride'], conv_param_5['pad']))
    self.layers.append(Relu())
    self.layers.append(Convolution(self.params['W6'], self.params['b6'],
                       conv_param_6['stride'], conv_param_6['pad']))
    self.layers.append(Relu())
    self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
    self.layers.append(Affine(self.params['W7'], self.params['b7']))
    self.layers.append(Relu())
    self.layers.append(Dropout(0.5))
    self.layers.append(Affine(self.params['W8'], self.params['b8']))
    self.layers.append(Dropout(0.5))`