Moez B commited on
Commit
b866286
·
1 Parent(s): b5c2ad5

first deploy pls work

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.keras filter=lfs diff=lfs merge=lfs -text
.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
.idea/Surgical-Tool-Segmentation.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="jdk" jdkName="Python 3.11 (CU-There)" jdkType="Python SDK" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="Python 3.11 (CU-There)" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (CU-There)" project-jdk-type="Python SDK" />
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/Surgical-Tool-Segmentation.iml" filepath="$PROJECT_DIR$/.idea/Surgical-Tool-Segmentation.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ #load all models at the start
7
+ unet_path = hf_hub_download(repo_id="treephones/tool-seg-unet", filename="1_simple_unet.keras")
8
+ resnet_path = hf_hub_download(repo_id="treephones/tool-seg-resnet50-unet", filename="2_resnet50_unet.keras")
9
+ fcn_path = hf_hub_download(repo_id="treephones/tool-seg-fcn-8s", filename="3_fcn_8s.keras")
10
+
11
+ unet = tf.keras.models.load_model(unet_path, compile=False)
12
+ rn50_unet = tf.keras.models.load_model(resnet_path, compile=False)
13
+ fcn_8s = tf.keras.models.load_model(fcn_path, compile=False)
14
+ #preprocess
15
+ def preprocess_image(img: Image.Image):
16
+ img = img.convert("RGB").resize((256, 256))
17
+ img = np.array(img).astype(np.float32) / 255.0
18
+ return np.expand_dims(img, axis=0)
19
+
20
+ #predict
21
+ def predict_all_models(img):
22
+ tensor = preprocess_image(img)
23
+
24
+ out1 = unet.predict(tensor)[0]
25
+ out2 = rn50_unet.predict(tensor)[0]
26
+ out3 = fcn_8s.predict(tensor)[0]
27
+
28
+ out1_img = Image.fromarray((out1 * 255).astype(np.uint8))
29
+ out2_img = Image.fromarray((out2 * 255).astype(np.uint8))
30
+ out3_img = Image.fromarray((out3 * 255).astype(np.uint8))
31
+
32
+ return out1_img, out2_img, out3_img
33
+
34
+ #gradio stuff
35
+ demo = gr.Interface(
36
+ fn=predict_all_models,
37
+ inputs=gr.Image(label="Upload an Image", type="pil"),
38
+ outputs=[
39
+ gr.Image(label="Simple U-Net Output"),
40
+ gr.Image(label="ResNet50 + U-Net Output"),
41
+ gr.Image(label="FCN-8s Output")
42
+ ],
43
+ title="Tool Segmentation Comparison with Multiple Models",
44
+ description="Upload a single image to see how each segmentation model performs."
45
+ )
46
+
47
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ numpy
4
+ pillow
5
+ huggingface_hub