File size: 932 Bytes
13964f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36370eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()