nazlicanto commited on
Commit
ad0ef4b
1 Parent(s): 355d137

Resolved merge conflicts

Browse files
Files changed (1) hide show
  1. app06.py +0 -40
app06.py CHANGED
@@ -40,43 +40,3 @@ if uploaded_file:
40
  # Display the results
41
  st.image(test_image, caption="Uploaded Image", use_column_width=True)
42
  st.image(semantic_map, caption="Predicted Defects", use_column_width=True, channels="GRAY")
43
- =======
44
-
45
- import streamlit as st
46
- from transformers import SegformerForSemanticSegmentation, SegformerImageProcessor
47
- from PIL import Image
48
- import numpy as np
49
- import torch
50
-
51
- # Load the model and processor
52
- model_dir = "/home/user/app/defectdetection/model"
53
- model = SegformerForSemanticSegmentation.from_pretrained(model_dir)
54
- processor = SegformerImageProcessor.from_pretrained(model_dir)
55
- model.eval()
56
-
57
- st.title("PCB Defect Detection")
58
-
59
- # Upload image in Streamlit
60
- uploaded_file = st.file_uploader("Upload a PCB image", type=["jpg", "png"])
61
-
62
- if uploaded_file:
63
- # Preprocess the image
64
- test_image = Image.open(uploaded_file).convert("RGB")
65
- inputs = processor(images=test_image, return_tensors="pt")
66
-
67
- # Model inference
68
- with torch.no_grad():
69
- outputs = model(**inputs)
70
-
71
- # Post-process
72
- semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[test_image.size[::-1]])[0]
73
- semantic_map = np.uint8(semantic_map)
74
- semantic_map[semantic_map==1] = 255
75
- semantic_map[semantic_map==2] = 195
76
- semantic_map[semantic_map==3] = 135
77
- semantic_map[semantic_map==4] = 75
78
-
79
- # Display the results
80
- st.image(test_image, caption="Uploaded Image", use_column_width=True)
81
- st.image(semantic_map, caption="Predicted Defects", use_column_width=True, channels="GRAY")
82
- >>>>>>> 36ac725dd03eaeedd3c4601d12a8b80b846b7647
 
40
  # Display the results
41
  st.image(test_image, caption="Uploaded Image", use_column_width=True)
42
  st.image(semantic_map, caption="Predicted Defects", use_column_width=True, channels="GRAY")