0

i'm training a neural network model using tensorflow , for image segmentation , and i want to be able to extract the images after training, from the final logits layer

here is the decoder part of my model

DECODER

upsampling layer 1 :

upsample1 = tf.image.resize_images(pool5, size=(200, 200), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

Deconvolutional layer 1 :
deconv1 = tf.layers.conv2d_transpose(inputs=upsample1, filters=512, kernel_size=(3, 3),strides=(1, 1),  padding='same',
                                     activation=tf.nn.relu)
deconv1bis = tf.layers.conv2d_transpose(inputs=deconv1, filters=512, kernel_size=(3, 3),strides=(1, 1),  padding='same',
                                        activation=tf.nn.relu)
deconv1bisbis = tf.layers.conv2d_transpose(inputs=deconv1bis, filters=512, kernel_size=(3, 3),strides=(1, 1),  padding='same',
                                           activation=tf.nn.relu)

upsampling layer 2 :

upsample2 = tf.image.resize_images(deconv1bisbis, size=(200, 200),  method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

Deconvolutional layer 2 :

deconv2 = tf.layers.conv2d_transpose(inputs=upsample2, filters=512,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                     activation=tf.nn.relu)
deconv2bis = tf.layers.conv2d_transpose(inputs=deconv2, filters=512,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                        activation=tf.nn.relu)
deconv2bisbis = tf.layers.conv2d_transpose(inputs=deconv2bis, filters=512, strides=(1, 1), kernel_size=(3, 3), padding='same',
                                           activation=tf.nn.relu)

upsampling layer 3 :

upsample3 = tf.image.resize_images(deconv2bisbis, size=(200, 200),  method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

Deconvolutional layer 3 :

deconv3 = tf.layers.conv2d_transpose(inputs=upsample3, filters=256,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                     activation=tf.nn.relu)
deconv3bis = tf.layers.conv2d_transpose(inputs=deconv3, filters=256,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                        activation=tf.nn.relu)
deconv3bisbis = tf.layers.conv2d_transpose(inputs=deconv3bis, filters=512,strides=(1, 1), kernel_size=(3, 3), padding='same',
                                           activation=tf.nn.relu)

upsampling layer 4 :

upsample4 = tf.image.resize_images(deconv3bisbis, size=(200, 200),  method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

Deconvolutional layer 4 :

deconv4 = tf.layers.conv2d_transpose(inputs=upsample4, filters=128,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                     activation=tf.nn.relu)
deconv4bis = tf.layers.conv2d_transpose(inputs=deconv4, filters=128,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                        activation=tf.nn.relu)

upsampling layer 5 :

upsample5 = tf.image.resize_images(deconv4bis, size=(200, 200),  method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

Deconvolutional layer 5 :

deconv5 = tf.layers.conv2d_transpose(inputs=upsample5, filters=64,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                     activation=tf.nn.relu)
deconv5bis = tf.layers.conv2d_transpose(inputs=deconv5, filters=64,strides=(1, 1),  kernel_size=(3, 3), padding='same',
                                        activation=tf.nn.relu)

Logits Layer

logits = tf.layers.dense(inputs=deconv5bis, units=1, activation=tf.nn.relu)

any one have an idea how i can do that ?

trotta
  • 1,232
  • 1
  • 16
  • 23
  • It's not clear what you're asking here, `logits` here seems to be a single number since `units=1`. How do you expect to turn this into an image? – Yolo Swaggins Jun 26 '19 at 17:39
  • hello @YoloSwaggins , i'm new to programming , so i know that my code has a lot of mistakes , and perhaps there is some things that i don't understand , so how can i modify logits to turn it after to an image !! here my goal is to train a stack of images for segmentation, obtained by x-ray tomography , so i want to be able to have my input , and output image (after training) , so i can be able to compare between them two , – Kawtar El Amiry Jun 27 '19 at 11:41
  • Don't worry about being new, everyone is new when they first start. It's just not clear, do you need `logits` for training, or are we free to modify it as we wish? Think about it without any programming, if I give you a single number can you turn that into an image for me? It's clear that task is very difficult. – Yolo Swaggins Jun 27 '19 at 12:35
  • i'm actually not sure if "logits= tf.layers.dense" is the right function here , i'm trying to implement Seg-Net model and in the documentation it says that the last layer should be a softmax function but my supervisor told me that this function is the right one , but if you have any suggestions don't hesitate , i can modify the code as i want :) – Kawtar El Amiry Jun 27 '19 at 13:56
  • Anyone can help ? :') – Kawtar El Amiry Jun 30 '19 at 23:11

1 Answers1

0

I guess what you mean by :

I want to be able to extract the images after training, from the final logits layer

Well, actually this doesn't work this way. But don't worry, I guess you meant that you want to see how you can see the segmentation or the masks on the images after you finish the training of your neural network.

Here we are talking about the prediction part after the training is done.

Once you are done, you can take any image you want and apply this model to output the segmentation results on it.

The output will in the form of a number (probability) in case of classification problem, or a sequence of integers that locate the mask on the image, ... etc.

You may find the answer here: Tensorflow: how to run prediction (using an image as input) for a trained model?

Just as a note that would be helpful, I highly recommend starting with Keras if you are a starter with deep learning. Tensorflow is a great tool but it's low level and requires more complicated details that you don't need to know.

I hope this could help.

smerllo
  • 3,117
  • 1
  • 22
  • 37