SketchToImage / app.py
lee45's picture
Update app.py
36370eb
raw
history blame contribute delete
932 Bytes
import gradio as gr
import numpy as np
import pandas as pd
import cv2
import os
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
import matplotlib
def dice_loss(y_true, y_pred):
smooth = 1.
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = y_true_f * y_pred_f
score = (2. * K.sum(intersection) + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
return 1. - score
from keras.models import load_model
model = load_model('model91.h5',custom_objects={'dice_loss':dice_loss})
def convert_sketch(img):
img = cv2.resize(img,(178,218))
img = img.astype(np.float32)/255.
y_pred = model.predict(img.reshape(1,218,178,3))
return(y_pred[0])
custom_text = "hello"
gr.Interface(fn=convert_sketch,inputs="image",outputs="image",title="Sketch To Image Converter",description="Warning: Upload the sketches of 178*218 pixels to get accurate results.").launch()