Rohankumar31 commited on
Commit
78de175
·
verified ·
1 Parent(s): 5f9422e

Upload 2 files

Browse files
Files changed (2) hide show
  1. best (1).pt +3 -0
  2. sample.py +55 -0
best (1).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3dbe7873c29c002885d80f22a0617585be6a70766ad7585dfec5b57548e9da2
3
+ size 52035329
sample.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import torch
4
+ from torchvision import transforms
5
+
6
+ # Load the YOLO model
7
+ @st.cache
8
+ def load_model():
9
+ # Replace 'model.pt' with the path to your YOLO model file
10
+ model = torch.load('best.pt')
11
+ return model
12
+
13
+ # Define YOLO processing function
14
+ def process_image(image, model):
15
+ # Preprocess the image
16
+ preprocess = transforms.Compose([
17
+ transforms.Resize((416, 416)),
18
+ transforms.ToTensor(),
19
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
20
+ ])
21
+ input_tensor = preprocess(image)
22
+ input_batch = input_tensor.unsqueeze(0)
23
+
24
+ # Perform inference
25
+ with torch.no_grad():
26
+ output = model(input_batch)
27
+
28
+ # Post-process the output (e.g., draw bounding boxes)
29
+ # Replace this with your post-processing code
30
+
31
+ # Convert tensor to PIL Image
32
+ output_image = transforms.ToPILImage()(output[0].cpu().squeeze())
33
+
34
+ return output_image
35
+
36
+ # Main Streamlit code
37
+ def main():
38
+ st.title('YOLO Image Detection')
39
+
40
+ # Upload image file
41
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
42
+
43
+ if uploaded_file is not None:
44
+ # Load YOLO model
45
+ model = load_model()
46
+
47
+ # Process uploaded image
48
+ image = Image.open(uploaded_file)
49
+ st.image(image, caption='Original Image', use_column_width=True)
50
+
51
+ output_image = process_image(image, model)
52
+ st.image(output_image, caption='Processed Image', use_column_width=True)
53
+
54
+ if __name__ == '__main__':
55
+ main()