Spaces:
Sleeping
Sleeping
first
Browse files- app.py +58 -0
- model/fingerprint.pb +3 -0
- model/saved_model.pb +3 -0
- model/variables/variables.index +0 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import streamlit as st
|
5 |
+
import tensorflow as tf
|
6 |
+
|
7 |
+
|
8 |
+
def process_image(uploaded_file):
|
9 |
+
file_content = uploaded_file.read()
|
10 |
+
nparr = np.frombuffer(file_content, np.uint8)
|
11 |
+
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
12 |
+
return image
|
13 |
+
|
14 |
+
|
15 |
+
model = tf.saved_model.load("./model")
|
16 |
+
|
17 |
+
|
18 |
+
def perform_segmentation(image):
|
19 |
+
resized_image = cv2.resize(image, (128, 128))
|
20 |
+
resized_image = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB)
|
21 |
+
normalized_image = resized_image / 255.0
|
22 |
+
|
23 |
+
input_array = np.expand_dims(normalized_image, axis=0).astype(np.float32)
|
24 |
+
segmented_mask = model(tf.constant(input_array))[0]
|
25 |
+
|
26 |
+
threshold = 0.5
|
27 |
+
binary_mask = (segmented_mask > threshold).numpy().astype(np.uint8)
|
28 |
+
|
29 |
+
# Resize the binary mask to match the size of the input image
|
30 |
+
binary_mask_resized = cv2.resize(binary_mask, (image.shape[1], image.shape[0]))
|
31 |
+
|
32 |
+
segmented_image = cv2.bitwise_and(image, image, mask=binary_mask_resized)
|
33 |
+
|
34 |
+
return segmented_image
|
35 |
+
|
36 |
+
|
37 |
+
def main():
|
38 |
+
st.title("Solution Challenge")
|
39 |
+
|
40 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
41 |
+
if uploaded_file is not None:
|
42 |
+
image = process_image(uploaded_file)
|
43 |
+
segmented_image = perform_segmentation(image)
|
44 |
+
|
45 |
+
# Create two columns to display images side by side
|
46 |
+
col1, col2 = st.columns(2)
|
47 |
+
|
48 |
+
# Display original image in the first column
|
49 |
+
col1.image(image, caption="Original Image", use_column_width=True)
|
50 |
+
|
51 |
+
# Display segmented image in the second column
|
52 |
+
col2.image(
|
53 |
+
segmented_image, caption="Segmentation Results", use_column_width=True
|
54 |
+
)
|
55 |
+
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
main()
|
model/fingerprint.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8bef387a304bfd676326f7d2ec4811ccae1f3bb1f4746953f3df145213f4fa67
|
3 |
+
size 55
|
model/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:732f4eba03c3087cc644415be96778eee346cb6a4799f6c19d9134aa7c7defda
|
3 |
+
size 1605495
|
model/variables/variables.index
ADDED
Binary file (14.7 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
tensorflow
|
3 |
+
opencv-python
|