gwding / draw_convnet

2.64k stars 513 forks source link

Not able to add layers #10

Closed akshataman closed 6 years ago

akshataman commented 6 years ago

I need to add more convolution layers in my model. But I am not able to understand the code to do so. Can you please help me to do so?

Below is the visualization of model which I want to make. Please help.

Layer (type) Output Shape Param #

conv2d_11 (Conv2D) (None, 126, 126, 16) 448


conv2d_12 (Conv2D) (None, 124, 124, 32) 4640


max_pooling2d_9 (MaxPooling2 (None, 62, 62, 32) 0


conv2d_13 (Conv2D) (None, 60, 60, 32) 9248


max_pooling2d_10 (MaxPooling (None, 30, 30, 32) 0


conv2d_14 (Conv2D) (None, 28, 28, 32) 9248


max_pooling2d_11 (MaxPooling (None, 14, 14, 32) 0


conv2d_15 (Conv2D) (None, 12, 12, 32) 9248


max_pooling2d_12 (MaxPooling (None, 6, 6, 32) 0


dropout_5 (Dropout) (None, 6, 6, 32) 0


flatten_3 (Flatten) (None, 1152) 0


dense_5 (Dense) (None, 32) 36896


dropout_6 (Dropout) (None, 32) 0


dense_6 (Dense) (None, 3) 99

Total params: 69,827 Trainable params: 69,827 Non-trainable params: 0

gwding commented 6 years ago

you'll need to modify these lists in order to add layers. layer parameters are distributed in these lists and in order.

############################

conv layers

size_list = [(32, 32), (18, 18), (10, 10), (6, 6), (4, 4)] num_list = [3, 32, 32, 48, 48] x_diff_list = [0, layer_width, layer_width, layer_width, layer_width] text_list = ['Inputs'] + ['Feature\nmaps'] (len(size_list) - 1) loc_diff_list = [[3, -3]] len(size_list) ############################

in between layers

start_ratio_list = [[0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8]] end_ratio_list = [[0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8]] patch_size_list = [(5, 5), (2, 2), (5, 5), (2, 2)] ind_bgn_list = range(len(patch_size_list)) text_list = ['Convolution', 'Max-pooling', 'Convolution', 'Max-pooling']

############################

fully connected layers

size_list = [(fc_unit_size, fc_unit_size)] 3 num_list = [768, 500, 2] num_show_list = list(map(min, num_list, [NumFcMax] len(num_list))) x_diff_list = [sum(x_diff_list) + layer_width, layer_width, layer_width] top_leftlist = np.c[np.cumsum(x_diff_list), np.zeros(len(x_diff_list))] loc_diff_list = [[fc_unit_size, -fc_unit_size]] len(top_left_list) text_list = ['Hidden\nunits'] (len(size_list) - 1) + ['Outputs']

On Wed, 20 Jun 2018 at 05:30, Akshat Aman notifications@github.com wrote:

I need to add more convolution layers in my model. But I am not able to understand the code to do so. Can you please help me to do so?

Below is the visualization of model which I want to make. Please help. Layer (type) Output Shape Param #

conv2d_11 (Conv2D) (None, 126, 126, 16) 448

conv2d_12 (Conv2D) (None, 124, 124, 32) 4640

max_pooling2d_9 (MaxPooling2 (None, 62, 62, 32) 0

conv2d_13 (Conv2D) (None, 60, 60, 32) 9248

max_pooling2d_10 (MaxPooling (None, 30, 30, 32) 0

conv2d_14 (Conv2D) (None, 28, 28, 32) 9248

max_pooling2d_11 (MaxPooling (None, 14, 14, 32) 0

conv2d_15 (Conv2D) (None, 12, 12, 32) 9248

max_pooling2d_12 (MaxPooling (None, 6, 6, 32) 0

dropout_5 (Dropout) (None, 6, 6, 32) 0

flatten_3 (Flatten) (None, 1152) 0

dense_5 (Dense) (None, 32) 36896

dropout_6 (Dropout) (None, 32) 0

dense_6 (Dense) (None, 3) 99

Total params: 69,827 Trainable params: 69,827 Non-trainable params: 0

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gwding/draw_convnet/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AG7ZutwU1szcItifG5raqR4Oq6Ud6Im9ks5t-hYxgaJpZM4Uu7Ai .

akshataman commented 6 years ago

convnet_fig

I somehow added these layers but I'm facing problem in patch_size_list! After increasing the size, the error comes out to be "index 11 is out of bounds for axis 0 with size 11" I'm sending you the code screenshot!

screenshot 1

Can you please suggest me the essential changes so as to fit my model.

gwding commented 6 years ago

@akshataman if you haven't figured it out, can you copy the full error message to here?

akshataman commented 6 years ago

IndexError Traceback (most recent call last)

in () 165 patch_size_list[ind], ind, 166 top_left_list, loc_diff_list, num_show_list, size_list) --> 167 label(top_left_list[ind], text_list[ind] + '\n{}x{} kernel'.format( 168 patch_size_list[ind][0], patch_size_list[ind][1]), xy_off=[26, -65] 169 ) IndexError: list index out of range This error is coming while I changed the parameters below: ############################ # in between layers start_ratio_list = [[0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5]] end_ratio_list = [[0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5], [0.4, 0.8], [0.4, 0.5]] patch_size_list = [(3, 3), (2, 2), (3, 3), (2, 2), (2, 2), (3, 3), (2, 2), (2, 2), (3, 3), (2, 2), (2, 2)] ind_bgn_list = range(len(patch_size_list)) text_list = ['Convolution', 'Convolution', 'Max-pooling', 'Convolution', 'Max-pooling', 'Convolution', 'Max-pooling', 'Dropout', 'Flatten'] for ind in range(len(patch_size_list)): add_mapping( patches, colors, start_ratio_list[ind], end_ratio_list[ind], patch_size_list[ind], ind, top_left_list, loc_diff_list, num_show_list, size_list) label(top_left_list[ind], text_list[ind] + '\n{}x{} kernel'.format( patch_size_list[ind][0], patch_size_list[ind][1]), xy_off=[26, -65] ) Below is the model which I want. It's urgent. Please suggest me how to do that. ![mymodel](https://user-images.githubusercontent.com/22327666/41697785-1793a766-7538-11e8-8ec9-ee5e5d3c7044.jpg)
gwding commented 6 years ago

you'll need to make sure the length of lists make sense. e.g. for in-between layers lists, you need them to have the same length. length of "in-between" lists should be n-1, where n is the number layers.