简体   繁体   中英

Keras: feed images into CNN and get image output

So far, I've been practicing neural networks on numerical datasets in pandas, but now I need to create a model that will take an image as input and output a binary mask of that image.

I have my training data as numpy arrays of shape (602, 2048, 2048, 1). 602 images of dimensions 2048x2048 with one channel. The array of output masks have the same dimensions.

What I can't figure out is how to define the first layer or how to correctly feed the data into the model. I would greatly appreciate your help on this issue

Well, this is not a "rule", but probably you will be using mostly 2D conv and related layers.

You feed everything as numpy arrays, as usual, maybe normalizing the values. Common options are:

  • Between 0 and 1 (just divide by 255.)
  • Between -1 and 1 (divide by 255., multiply by 2, subtract 1)
  • Caffe style: subtract from each channel a specific value to "center" the values based on their usual mean without rescaling them.

Your model should start with something like:

inputTensor = Input((2048,2048,1))
output = Conv2D(filters, kernel_size, .....)(inputTensor)    

Or, in sequential models: model.add(Conv2D(...., input_shape=(2048,2048,1))

Later, it's up to you to decide which layers to use.

  • Conv2D
  • MaxPooling2D
  • Upsampling2D

Whether you're going to create a linear model or if you're going to divide branches, join branches, etc. is also your call.

Models in a U-Net style should be a good start for you.

What you can't do :

  • Don't use Flatten layers (actually you can, if you later reshape the output for having image dimensions... but why?)
  • Don't use Global Pooling layers (you don't want to sacrifice your spatial dimensions)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM