3
$\begingroup$

I'm trying to build a CNN similar to this:

figure 1

For this purpose I chose to use Keras since I worked with it before (simple RNN and FFNN only). My training data consists of the input data (25 x 25px images) and the output, being 25 x 25px images as well. The problem is, that I don't know how to build the Model using Keras. How do I specify the output to be of the same shape as the input?

Here is what I have so far:

batch_size = 5
input_shape = (batch_size, 28, 28,  32)

model = Sequential()
model.add(Conv2D(32, kernel_size=(5, 5), strides=(1, 1),
                 activation='relu',
                 input_shape=input_shape))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(64, (5, 5), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Conv2D(64, (5, 5), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(32, kernel_size=(5, 5), strides=(1, 1),
                 activation='relu',
                 input_shape=input_shape))

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.SGD(lr=0.01),
              metrics=['accuracy'])

I know, that the code will not work like that. I just want to clarify what I'm trying to do. The code above was taken from: Keras tutorial – build a convolutional neural network in 11 lines

As of now I just tried to reverse the code from the point, where the tutorial would output the predicted label for the given image to transform the result back to the wanted output image.

$\endgroup$
1
  • $\begingroup$ Hi and welcome, would you please put a reference for your image? Is that a formal architechture introduced in a paper? $\endgroup$ Apr 17, 2018 at 6:11

1 Answer 1

1
$\begingroup$

I know this question was asked sometime ago. I took a look at the diagram and the example code. First, the example code is way off. Here's a description to help those curious how to understand the diagram.

The diagram (architecture) shows only the frontend of a CNN. That's the convolutional layers. On the leftside are a series of VGG convolution blocks. The links to the right side are identity links between the VGG convolution blocks, which pass through their own convolution before being matrix added into the output of the convolution block. The addition of the convolution on the identity link makes it a variant of a ResNet architecture.

The UV 224x224x2 would be the output from the convolutional frontend. It would then be flattened and passed into the DNN layers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.