import numpy import keras import gradio # Building the neural network model1 = keras.models.Sequential() model1.add(keras.layers.InputLayer(input_shape=(101, 636, 1))) model1.add(keras.layers.Conv2D(4, (9, 9), activation='relu', padding='same', strides=1)) model1.add(keras.layers.Conv2D(4, (9, 9), activation='relu', padding='same')) model1.add(keras.layers.Conv2D(8, (7, 7), activation='relu', padding='same', strides=1)) model1.add(keras.layers.Conv2D(8, (7, 7), activation='relu', padding='same')) model1.add(keras.layers.Conv2D(16, (5, 5), activation='relu', padding='same')) model1.add(keras.layers.Conv2D(16, (5, 5), activation='relu', padding='same', strides=1)) model1.add(keras.layers.Conv2D(16, (3, 3), activation='relu', padding='same')) model1.add(keras.layers.Conv2D(16, (3, 3), activation='relu', padding='same', strides=1)) model1.add(keras.layers.Conv2D(16, (2, 2), activation='relu', padding='same')) model1.add(keras.layers.Conv2D(16, (2, 2), activation='relu', padding='same', strides=1)) model1.add(keras.layers.UpSampling2D((1, 1))) model1.add(keras.layers.Conv2D(16, (2, 2), activation='relu', padding='same')) model1.add(keras.layers.UpSampling2D((1, 1))) model1.add(keras.layers.Conv2D(8, (3, 3), activation='relu', padding='same')) model1.add(keras.layers.UpSampling2D((1, 1))) model1.add(keras.layers.Conv2D(4, (7, 7), activation='tanh', padding='same')) model1.add(keras.layers.UpSampling2D((1, 1))) model1.add(keras.layers.Conv2D(3, (9, 9), activation='tanh', padding='same')) #Loading the weights in the architecture (The file should be stored in the same directory as the code) model1.load_weights('modelV13_500trained_1.h5') def predict(mask): X = numpy.round((mask/255.0))[numpy.newaxis, :, :, numpy.newaxis] v = model1.predict(X)*255 output = (v - v.min()) / (v.max() - v.min()) print(output.shape) return output[0, :, :, 0], output[0, :, :, 1], output[0, :, :, 2] demo = gradio.Interface(fn=predict, inputs=[gradio.Image(image_mode="L", source="canvas")], outputs=[gradio.Image(image_mode="L"), gradio.Image(image_mode="L"), gradio.Image(image_mode="L")]) demo.run()