Spaces:
Build error
Build error
Commit ·
ad15734
1
Parent(s): 75af313
Upload 5 files
Browse files- best.pt +3 -0
- best2.pt +3 -0
- detect_app.py +86 -0
- package.txt +1 -0
- requirements.txt +30 -0
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f720384e204e2cb1dec5f8b14c387d771609eaad8d6ddfb6b4992284df045547
|
| 3 |
+
size 133
|
best2.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0c71ac9f83a1690701d31927208ed8c5fee225652564b790547a046823633d65
|
| 3 |
+
size 133
|
detect_app.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
import streamlit as st #hh
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
from skimage.io import imsave
|
| 6 |
+
st.title("Hi,This is only test web application for extracting the Wall from image")
|
| 7 |
+
st.write("Made by otman heddouch")
|
| 8 |
+
st.write("Please upload image of house with Roof ,then the Wamm extracted from the image will be shown above after seconds.")
|
| 9 |
+
st.info("make sure the wall is very clear on the image")
|
| 10 |
+
#load the model
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_model_():
|
| 13 |
+
model = YOLO("best2.pt")
|
| 14 |
+
return model
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
model = load_model_()
|
| 18 |
+
|
| 19 |
+
image_streamlit = st.file_uploader("Upload your image",type=["jpg","png","jpeg"])
|
| 20 |
+
|
| 21 |
+
if image_streamlit != None:
|
| 22 |
+
st.image(image_streamlit)
|
| 23 |
+
with open("image.jpg",mode = "wb") as f:
|
| 24 |
+
f.write(image_streamlit.getbuffer())
|
| 25 |
+
img = model.predict(source="image.jpg",
|
| 26 |
+
stream=True, retina_masks=True)
|
| 27 |
+
new = None
|
| 28 |
+
original_img = cv2.imread("image.jpg")
|
| 29 |
+
for result in img:
|
| 30 |
+
mask = result.masks.cpu().numpy()
|
| 31 |
+
#cv2.imwrite("mask.jpg",mask.masks)
|
| 32 |
+
masks = mask.masks.astype(bool)
|
| 33 |
+
print(masks)
|
| 34 |
+
ori_img = result.orig_img
|
| 35 |
+
new = np.ones_like(ori_img, dtype=np.uint8)
|
| 36 |
+
new_ = np.ones_like(ori_img, dtype=np.uint8)
|
| 37 |
+
|
| 38 |
+
for m in masks:
|
| 39 |
+
new[m] = ori_img[m]
|
| 40 |
+
new_[m] = 0
|
| 41 |
+
cv2.imwrite("modified_image.png", new)
|
| 42 |
+
#cv2.imwrite("modified_image_.png", new_)
|
| 43 |
+
|
| 44 |
+
st.image("modified_image.png")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# from ultralytics import YOLO
|
| 49 |
+
# import streamlit as st
|
| 50 |
+
# import cv2
|
| 51 |
+
# import numpy as np
|
| 52 |
+
|
| 53 |
+
# st.title("Wall Extraction and Color Change")
|
| 54 |
+
# st.write("Made by Otman Heddouch")
|
| 55 |
+
# st.write("Please upload an image of a house with a roof. The extracted wall will be displayed above after a few seconds.")
|
| 56 |
+
# st.info("Make sure the wall is clear in the image.")
|
| 57 |
+
|
| 58 |
+
# # Load the model
|
| 59 |
+
# @st.cache_resource
|
| 60 |
+
# def load_model():
|
| 61 |
+
# model = YOLO("wall.pt")
|
| 62 |
+
# return model
|
| 63 |
+
|
| 64 |
+
# model = load_model()
|
| 65 |
+
|
| 66 |
+
# image_streamlit = st.file_uploader("Upload your image", type=["jpg", "png", "jpeg"])
|
| 67 |
+
|
| 68 |
+
# if image_streamlit is not None:
|
| 69 |
+
# st.image(image_streamlit)
|
| 70 |
+
# with open("image.jpg", mode="wb") as f:
|
| 71 |
+
# f.write(image_streamlit.getbuffer())
|
| 72 |
+
|
| 73 |
+
# img = model.predict(source="image.jpg", stream=True, retina_masks=True)
|
| 74 |
+
# original_img = cv2.imread("image.jpg")
|
| 75 |
+
|
| 76 |
+
# for result in img:
|
| 77 |
+
# mask = result.masks.cpu().numpy()
|
| 78 |
+
# masks = mask.masks.astype(bool)
|
| 79 |
+
|
| 80 |
+
# modified_img = original_img.copy()
|
| 81 |
+
# new_color = np.array([0, 255, 0], dtype=np.uint8) # Green color, you can adjust the values accordingly
|
| 82 |
+
# modified_img[masks] = new_color
|
| 83 |
+
|
| 84 |
+
# cv2.imwrite("modified_image.png", modified_img)
|
| 85 |
+
# st.image("modified_image.png")
|
| 86 |
+
|
package.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
libgl1
|
requirements.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# YOLOv5 requirements
|
| 2 |
+
# Usage: pip install -r requirements.txt
|
| 3 |
+
|
| 4 |
+
# Base ----------------------------------------
|
| 5 |
+
matplotlib>=3.2.2
|
| 6 |
+
numpy>=1.18.5
|
| 7 |
+
opencv-python-headless
|
| 8 |
+
Pillow>=7.1.2
|
| 9 |
+
PyYAML>=5.3.1
|
| 10 |
+
requests>=2.23.0
|
| 11 |
+
scipy>=1.4.1 # Google Colab version
|
| 12 |
+
torch>=1.7.0
|
| 13 |
+
torchvision>=0.8.1
|
| 14 |
+
scikit-image
|
| 15 |
+
tqdm>=4.41.0
|
| 16 |
+
protobuf<4.21.5 # https://github.com/ultralytics/yolov5/issues/8012
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Plotting ------------------------------------
|
| 20 |
+
pandas>=1.1.4
|
| 21 |
+
seaborn>=0.11.0
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Extras --------------------------------------
|
| 25 |
+
ipython # interactive notebook
|
| 26 |
+
psutil # system utilization
|
| 27 |
+
thop # FLOPs computation
|
| 28 |
+
streamlit
|
| 29 |
+
wget
|
| 30 |
+
ultralytics
|