|
| 1 | +from tensorflow.keras import Model, layers, Input |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +temp_im_test = np.ones((1,128,128,3)) |
| 5 | + |
| 6 | +input_shape_img = (128,128,3) |
| 7 | + |
| 8 | +img_input = Input(shape=input_shape_img) |
| 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) |
| 13 | + |
| 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) |
| 16 | + |
| 17 | +# globalmax layer |
| 18 | +globalmax1 = layers.GlobalMaxPool2D()(max1) |
| 19 | + |
| 20 | +# flattens input to 1D array |
| 21 | +flatten1 = layers.Flatten()(globalmax1) |
| 22 | + |
| 23 | +# dropout layer modifies input layer so some values become 0 |
| 24 | +drop1 = layers.Dropout(.2)(flatten1) |
| 25 | + |
| 26 | +# standard dense layer |
| 27 | +dense1 = layers.Dense(32)(drop1) |
| 28 | + |
| 29 | +# compiles model with input: img_input and output as output from dense1 |
| 30 | +model = Model(inputs = img_input, outputs= dense1) |
| 31 | +model.compile(optimizer='sgd', loss='mse') |
| 32 | + |
| 33 | +# shows model |
| 34 | +model.summary() |
| 35 | + |
| 36 | +# show result on one input |
| 37 | +values = model.predict(temp_im_test) |
| 38 | +print(values.shape) |
| 39 | +print(values) |
0 commit comments