python – Creating a Keras CNN for image alteration

python – Creating a Keras CNN for image alteration

I think you made two mistakes in your code:

  1. Instead of using Conv3D, you need to use Conv2D.
  2., output_img) should be, outputs).

The reason why you need to use Conv2D is the shape of your data is (length,width,channel), it doesnt possess an extra dimension.

Try the script below

#!/usr/bin/env python3
import tensorflow as tf
import pandas as pd
import numpy as np

def create_model(image_shape, batch_size = 10):
    width, height, channels = image_shape
    conv_shape = (width, height, channels)
    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Conv2D(filters = channels, kernel_size = 3, input_shape = conv_shape, padding = same))
    model.add(tf.keras.layers.Dense(channels, activation = relu))
    return model

if __name__ == __main__:
    image_shape = (32, 16, 5)

    # Create test input/output data sets:
    input_img = np.random.rand(*image_shape) # Create one dummy input image
    output_img = np.random.rand(*image_shape) # Create one dummy output image

    # Create a bogus training set by copying the input/output images into lists many times
    inputs = np.array([input_img]*500)
    outputs = np.array([output_img]*500)

    # Create the model and fit it to the dummy data
    model = create_model(image_shape)
    model.compile(loss = mean_squared_error, optimizer = adam, metrics = [accuracy]), outputs)

python – Creating a Keras CNN for image alteration

Leave a Reply

Your email address will not be published.