File size: 1,729 Bytes
1362442
 
 
 
 
 
 
ade5aef
1362442
 
db0638d
1362442
 
 
 
 
 
 
 
 
 
1379f3f
 
 
 
91f5a8b
 
 
 
9511827
1362442
 
5bdf2ef
 
f5803bc
 
 
 
5bdf2ef
 
 
 
 
 
 
1362442
 
5bdf2ef
 
 
 
 
a1d60ae
5bdf2ef
db0638d
4a2e709
db0638d
 
4a2e709
1362442
 
 
 
 
 
 
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
from detecto import core, utils, visualize
from detecto.visualize import show_labeled_image, plot_prediction_grid
from torchvision import transforms
import matplotlib.pyplot as plt
from tensorflow.keras.utils import img_to_array
import numpy as np
import warnings
from PIL import Image
import streamlit as st
warnings.filterwarnings("ignore", category=UserWarning) 
from tempfile import NamedTemporaryFile




MODEL_PATH = "SD_model_weights.pth"
IMAGE_PATH = "img1.jpeg"
model = core.Model.load(MODEL_PATH, ['cross_arm','pole','tag'])
#warnings.warn(msg)

st.title("Object Detection")
image = utils.read_image(IMAGE_PATH) 
predictions = model.predict(image)
labels, boxes, scores = predictions

images = ["img1.jpeg","img2.jpeg","img3.jpeg","img3.jpeg"]
with st.sidebar:
    st.write("choose an image")
    st.image(images)



def detect_object(IMAGE_PATH):
    image = utils.read_image(IMAGE_PATH) 
  #  predictions = model.predict(image)
   # labels, boxes, scores = predictions


    thresh=0.2
    filtered_indices=np.where(scores>thresh)
    filtered_scores=scores[filtered_indices]
    filtered_boxes=boxes[filtered_indices]
    num_list = filtered_indices[0].tolist()
    filtered_labels = [labels[i] for i in num_list]
    st.show_labeled_image(image, filtered_boxes, filtered_labels)
    #img_array = img_to_array(img)

file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))

if file is None:
    st.write("Please upload an image file")
else:
    image= Image.open(file)
    st.image(image,use_column_width = True)
    with NamedTemporaryFile(dir='.', suffix='.csv') as f:
        f.write(file.getbuffer())
    #your_function_which_takes_a_path(f.name)
   
        detect_object(f.name)