Spaces:
Runtime error
Runtime error
File size: 2,215 Bytes
17a270d edb8a3c 17a270d 10b1625 edb8a3c 10b1625 edb8a3c 10b1625 15ba74e edb8a3c 15ba74e 10b1625 f979b85 15ba74e 17a270d |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import gradio as gr
from layers import BilinearUpSampling2D
import matplotlib.pyplot as plt
import numpy as np
from huggingface_hub import from_pretrained_keras
custom_objects = {'BilinearUpSampling2D': BilinearUpSampling2D, 'depth_loss_function': None}
print('Loading model...')
model = from_pretrained_keras("keras-io/monocular-depth-estimation", custom_objects=custom_objects, compile=False)
print('Successfully loaded model...')
import importlib
import utils
importlib.reload(utils)
def infer(image, min_th, max_th):
print('_'*20)
inputs = utils.load_images([image])
outputs = utils.predict(model, inputs)
plasma = plt.get_cmap('plasma')
rescaled = outputs[0][:, :, 0]
print("Min Max Bef", np.min(rescaled), np.max(rescaled))
rescaled = rescaled - np.min(rescaled)
rescaled = rescaled / np.max(rescaled)
image_out = plasma(rescaled)[:, :, :3]
print("Min Max Aft", np.min(rescaled), np.max(rescaled))
print("Shape Scaled:",rescaled.shape)
filtered = rescaled
# filtered[filtered[:, :, 0] < min_th/100, 0] = 0
# filtered[filtered[:, :, 0] < min_th/100, 1] = 0
# filtered[filtered[:, :, 0] < min_th/100, 2] = 0
# filt_arr = filtered[((filtered[:,0] > min_th/100) & (filtered[:,0] < max_th/100))]
filt_arr = (filtered > min_th/100) * filtered * (filtered < max_th/100)
print("Shape Image:",image.shape)
print("Shape Image filt:",im_filt.shape)
print("Shape Image Heat:",image_out.shape)
im_filt = plasma(filt_arr)[:, :, :3]
return image_out, im_filt, image
# def detr(im):
# return im
gr_input = [
gr.inputs.Image(label="image", type="numpy", shape=(640, 480))
,gr.inputs.Slider(minimum=0, maximum=100, step=5, default=0, label="Minimum Threshold")
,gr.inputs.Slider(minimum=0, maximum=100, step=5, default=100, label="Maximum Threshold")
]
gr_output = [
gr.outputs.Image(type="pil",label="HeatMap Image"),
gr.outputs.Image(type="pil",label="Filtered Image"),
gr.outputs.Image(type="pil",label="Output Image")
]
iface = gr.Interface(
fn=infer,
title="Space Title Here",
description = "Description Here",
inputs = gr_input,
outputs = gr_output
)
iface.launch() |