Commit
·
142c453
1
Parent(s):
c22debf
Update Dockerfile to load garb cls model in build-time
Browse files- Dockerfile +4 -0
- app.py +21 -32
- statics/index.html +7 -2
- statics/style.css +8 -2
Dockerfile
CHANGED
@@ -52,9 +52,13 @@ COPY --chown=user . $HOME/app
|
|
52 |
|
53 |
# Pre-download all Hugging Face models
|
54 |
RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/detr-resnet-50', local_dir='/home/user/app/model/detr', local_dir_use_symlinks=False)"
|
|
|
55 |
RUN wget -O $HOME/app/model/garbage_detector.pt https://huggingface.co/BinKhoaLe1812/Garbage_Detection/resolve/main/garbage_detector.pt
|
56 |
RUN wget -O $HOME/app/model/yolov5-detect-trash-classification.pt https://huggingface.co/turhancan97/yolov5-detect-trash-classification/resolve/main/yolov5s.pt
|
|
|
57 |
RUN wget -O /home/user/app/model/yolov8n.pt https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt
|
|
|
|
|
58 |
|
59 |
# Verify model setup
|
60 |
RUN python setup.py
|
|
|
52 |
|
53 |
# Pre-download all Hugging Face models
|
54 |
RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/detr-resnet-50', local_dir='/home/user/app/model/detr', local_dir_use_symlinks=False)"
|
55 |
+
# External garbage detection models
|
56 |
RUN wget -O $HOME/app/model/garbage_detector.pt https://huggingface.co/BinKhoaLe1812/Garbage_Detection/resolve/main/garbage_detector.pt
|
57 |
RUN wget -O $HOME/app/model/yolov5-detect-trash-classification.pt https://huggingface.co/turhancan97/yolov5-detect-trash-classification/resolve/main/yolov5s.pt
|
58 |
+
# YOLOv8n garbage classification model
|
59 |
RUN wget -O /home/user/app/model/yolov8n.pt https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt
|
60 |
+
# YOLOv8s garbage classification model
|
61 |
+
RUN wget -O $HOME/app/model/garbage_cls_yolov8s.pt https://huggingface.co/BinKhoaLe1812/Garbage_Classification/resolve/main/garbage_cls_yolov8s/weights/best.pt
|
62 |
|
63 |
# Verify model setup
|
64 |
RUN python setup.py
|
app.py
CHANGED
@@ -187,39 +187,28 @@ def highlight_water_mask_on_frame(frame, binary_mask, color=(255, 0, 0), alpha=0
|
|
187 |
def astar(start, goal, occ):
|
188 |
h = lambda a,b: abs(a[0]-b[0])+abs(a[1]-b[1])
|
189 |
N8 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
|
190 |
-
openq=[(0,start)]; g={start:0}; came={}
|
191 |
while openq:
|
192 |
_,cur=heapq.heappop(openq)
|
193 |
if cur==goal:
|
194 |
p=[cur]; # reconstruct
|
195 |
while cur in came: cur=came[cur]; p.append(cur)
|
196 |
return p[::-1]
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
if
|
203 |
-
|
204 |
-
if abs(dx) == 1 and abs(dy) == 1:
|
205 |
-
if occ[cur[1]+dy, cur[0]] == 0 or occ[cur[1], cur[0]+dx] == 0:
|
206 |
continue
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
f
|
212 |
-
|
213 |
-
|
214 |
-
# Save visited search as debug image
|
215 |
-
visited_img = np.zeros_like(occ, dtype=np.uint8)
|
216 |
-
for x, y in visited:
|
217 |
-
visited_img[y, x] = 127
|
218 |
-
cv2.circle(visited_img, start[::-1], 3, 255, -1)
|
219 |
-
cv2.circle(visited_img, goal[::-1], 3, 255, -1)
|
220 |
-
cv2.imwrite("/home/user/app/outputs/debug_astar_failure.png", visited_img * 2)
|
221 |
-
print(f"🧨 A* failed from {start} to {goal} — frontier saved to debug_astar_failure.png")
|
222 |
-
return []
|
223 |
# KNN fit optimal path
|
224 |
def knn_path(start, targets, occ):
|
225 |
todo = targets[:]; path=[]
|
@@ -488,12 +477,12 @@ def _pipeline(uid,img_path):
|
|
488 |
centres.append([int((x1 + x2) / 2), int((y1 + y2) / 2)])
|
489 |
# add chunk centres and deduplicate
|
490 |
centres.extend(chunk_centres)
|
491 |
-
|
492 |
-
for
|
493 |
-
|
494 |
-
cv2.
|
495 |
-
|
496 |
-
|
497 |
if not centres: # No garbages within travelable zone
|
498 |
print(f"🛑 [{uid}] no reachable garbage"); video_ready[uid]=True; return
|
499 |
else: # Garbage within valid travelable zone
|
|
|
187 |
def astar(start, goal, occ):
|
188 |
h = lambda a,b: abs(a[0]-b[0])+abs(a[1]-b[1])
|
189 |
N8 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
|
190 |
+
openq=[(0,start)]; g={start:0}; came={}
|
191 |
while openq:
|
192 |
_,cur=heapq.heappop(openq)
|
193 |
if cur==goal:
|
194 |
p=[cur]; # reconstruct
|
195 |
while cur in came: cur=came[cur]; p.append(cur)
|
196 |
return p[::-1]
|
197 |
+
for dx,dy in N8:
|
198 |
+
nx,ny=cur[0]+dx,cur[1]+dy
|
199 |
+
# out-of-bounds / blocked
|
200 |
+
if not (0<=nx<640 and 0<=ny<640) or occ[ny,nx]==0: continue
|
201 |
+
# if diagonal, ensure both orthogonals are free
|
202 |
+
if abs(dx)==1 and abs(dy)==1:
|
203 |
+
if occ[cur[1]+dy, cur[0]]==0 or occ[cur[1], cur[0]+dx]==0:
|
|
|
|
|
204 |
continue
|
205 |
+
ng=g[cur]+1
|
206 |
+
if (nx,ny) not in g or ng<g[(nx,ny)]:
|
207 |
+
g[(nx,ny)]=ng
|
208 |
+
f=ng+h((nx,ny),goal)
|
209 |
+
heapq.heappush(openq,(f,(nx,ny)))
|
210 |
+
came[(nx,ny)]=cur
|
211 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
# KNN fit optimal path
|
213 |
def knn_path(start, targets, occ):
|
214 |
todo = targets[:]; path=[]
|
|
|
477 |
centres.append([int((x1 + x2) / 2), int((y1 + y2) / 2)])
|
478 |
# add chunk centres and deduplicate
|
479 |
centres.extend(chunk_centres)
|
480 |
+
# # Gray overlays for chunk centres that is movable - comment
|
481 |
+
# # centres = [list(c) for c in {tuple(c) for c in centres}]
|
482 |
+
# # for cx, cy in centres:
|
483 |
+
# # cv2.circle(movable_mask, (cx, cy), 3, 127, -1) # gray center dots
|
484 |
+
# # cv2.imwrite(f"{OUTPUT_DIR}/{uid}_movable_with_centres.png", movable_mask * 255)
|
485 |
+
# print(f"🧩 Saved debug movable_mask: {OUTPUT_DIR}/{uid}_movable_mask.png")
|
486 |
if not centres: # No garbages within travelable zone
|
487 |
print(f"🛑 [{uid}] no reachable garbage"); video_ready[uid]=True; return
|
488 |
else: # Garbage within valid travelable zone
|
statics/index.html
CHANGED
@@ -20,8 +20,13 @@
|
|
20 |
<div id="upload-container2">
|
21 |
<input type="file" id="upload2" accept="image/*">
|
22 |
<button id="checkAnimalBtn" onclick="uploadAnimal()">Check Animal</button>
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
<script src="/statics/script.js"></script>
|
26 |
</body>
|
27 |
</html>
|
|
|
20 |
<div id="upload-container2">
|
21 |
<input type="file" id="upload2" accept="image/*">
|
22 |
<button id="checkAnimalBtn" onclick="uploadAnimal()">Check Animal</button>
|
23 |
+
</div>
|
24 |
+
<div id="animal-result"></div>
|
25 |
+
<div id="upload-container3">
|
26 |
+
<input type="file" id="upload3" accept="image/*">
|
27 |
+
<button id="checkTrashBtn" onclick="uploadAnimal()">Check Animal</button>
|
28 |
+
</div>
|
29 |
+
<div id="trash-result"></div>
|
30 |
<script src="/statics/script.js"></script>
|
31 |
</body>
|
32 |
</html>
|
statics/style.css
CHANGED
@@ -8,10 +8,10 @@ h1 {
|
|
8 |
-webkit-background-clip: text;
|
9 |
font-weight: bold;
|
10 |
}
|
11 |
-
#upload-container, #upload-container2 {
|
12 |
background: rgba(255, 255, 255, 0.2); padding: 20px; width: 70%; border-radius: 10px; display: inline-block; box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.3);
|
13 |
}
|
14 |
-
#upload, #upload2 {
|
15 |
font-size: 18px; padding: 10px; border-radius: 5px; border: none; background: #fff; cursor: pointer;
|
16 |
}
|
17 |
#loader {
|
@@ -42,6 +42,12 @@ p {
|
|
42 |
#checkAnimalBtn:hover {
|
43 |
background: #8127ae;
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
.hidden {
|
46 |
display: none;
|
47 |
}
|
|
|
8 |
-webkit-background-clip: text;
|
9 |
font-weight: bold;
|
10 |
}
|
11 |
+
#upload-container, #upload-container2, #upload-container3 {
|
12 |
background: rgba(255, 255, 255, 0.2); padding: 20px; width: 70%; border-radius: 10px; display: inline-block; box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.3);
|
13 |
}
|
14 |
+
#upload, #upload2, #upload3 {
|
15 |
font-size: 18px; padding: 10px; border-radius: 5px; border: none; background: #fff; cursor: pointer;
|
16 |
}
|
17 |
#loader {
|
|
|
42 |
#checkAnimalBtn:hover {
|
43 |
background: #8127ae;
|
44 |
}
|
45 |
+
#checkTrashBtn {
|
46 |
+
display: block; width: 20%; margin-top: 20px; margin-left: auto; margin-right: auto; padding: 10px 15px; font-size: 16px; background: #147712; color: white; border: none; border-radius: 5px; cursor: pointer; text-decoration: none;
|
47 |
+
}
|
48 |
+
#checkTrashBtn:hover {
|
49 |
+
background: #105e5d;
|
50 |
+
}
|
51 |
.hidden {
|
52 |
display: none;
|
53 |
}
|