|
1 | 1 | from tensorflow.keras import Model, layers, Input |
2 | 2 | import numpy as np |
3 | 3 |
|
4 | | -temp_im_test = np.ones((1,128,128,3)) |
| 4 | +temp_im_test = np.random.rand(1,64,64,3) |
5 | 5 |
|
6 | | -input_shape_img = (128,128,3) |
| 6 | +input_shape_img = (64,64,3) |
7 | 7 |
|
8 | 8 | img_input = Input(shape=input_shape_img) |
9 | 9 |
|
10 | | -# convolutional layers with 64 neurons and (3,3) kernel each |
11 | | -conv1_1 = layers.Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input) |
12 | | -conv1_2 = layers.Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(conv1_1) |
| 10 | +# convolutional layers with 32 neurons and (3,3) kernel each |
| 11 | +conv1_1 = layers.Conv2D(32, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input) |
| 12 | +conv1_2 = layers.Conv2D(32, (3, 3), activation='relu', padding='same', name='block1_conv2')(conv1_1) |
13 | 13 |
|
14 | 14 | # maxpool2D layer with (2,2) filter and stride (2,2) |
15 | | -max1 = layers.MaxPool2D((2, 2), strides=(2, 2), name='block1_pool')(conv1_2) |
| 15 | +max1 = layers.MaxPool2D((2, 2), strides=(2, 2), name='block1_max_pool')(img_input) |
| 16 | + |
| 17 | +# avgpool2D layer with (2,2) filter and stride (2,2) |
| 18 | +avg1 = layers.AveragePooling2D((2, 2), strides=(2, 2), name='block1_avg_pool')(img_input) |
16 | 19 |
|
17 | 20 | # globalmax layer |
18 | | -globalmax1 = layers.GlobalMaxPool2D()(max1) |
| 21 | +globalmax1 = layers.GlobalMaxPool2D() |
19 | 22 |
|
20 | 23 | # flattens input to 1D array |
21 | | -flatten1 = layers.Flatten()(globalmax1) |
| 24 | +flatten1 = layers.Flatten()(avg1) |
22 | 25 |
|
23 | 26 | # dropout layer modifies input layer so some values become 0 |
24 | 27 | drop1 = layers.Dropout(.2)(flatten1) |
25 | 28 |
|
26 | 29 | # standard dense layer |
27 | | -dense1 = layers.Dense(32)(drop1) |
| 30 | +dense1 = layers.Dense(10)(drop1) |
28 | 31 |
|
29 | 32 | # compiles model with input: img_input and output as output from dense1 |
30 | 33 | model = Model(inputs = img_input, outputs= dense1) |
|
35 | 38 |
|
36 | 39 | # show result on one input |
37 | 40 | values = model.predict(temp_im_test) |
38 | | -print(values.shape) |
39 | | -print(values) |
| 41 | +print("shape of input" + str(temp_im_test.shape)) |
| 42 | +print("shape of output" + str(values.shape)) |
| 43 | +print(temp_im_test[0]) |
| 44 | +print(values[0]) |
0 commit comments