Add reco for gradio
Browse files- app.py +3 -2
- detect.py +5 -1
- hubconf.py +1 -1
app.py
CHANGED
|
@@ -133,7 +133,8 @@ def detect_logo(img, model, confidence):
|
|
| 133 |
for *xyxy, conf, cls in reversed(det):
|
| 134 |
name_class = names[int(cls.item())]
|
| 135 |
all_classes_detected.append(name_class)
|
| 136 |
-
|
|
|
|
| 137 |
if save_txt:
|
| 138 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()
|
| 139 |
line = (names[int(cls.item())], *xywh, conf) if opt.save_conf else (names[int(cls.item())], *xywh)
|
|
@@ -142,7 +143,7 @@ def detect_logo(img, model, confidence):
|
|
| 142 |
f.write(('%g ' * (len(line)-1)).rstrip() % line[1:] + '\n')
|
| 143 |
|
| 144 |
if save_img or view_img:
|
| 145 |
-
label = f'{names[int(cls)]} {conf:.2f}'
|
| 146 |
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)
|
| 147 |
if view_img:
|
| 148 |
cv2.imshow(str(p), im0)
|
|
|
|
| 133 |
for *xyxy, conf, cls in reversed(det):
|
| 134 |
name_class = names[int(cls.item())]
|
| 135 |
all_classes_detected.append(name_class)
|
| 136 |
+
name_recommanded = recommender.make_recommendation(name_class)
|
| 137 |
+
all_recommendations.append(name_recommanded)
|
| 138 |
if save_txt:
|
| 139 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()
|
| 140 |
line = (names[int(cls.item())], *xywh, conf) if opt.save_conf else (names[int(cls.item())], *xywh)
|
|
|
|
| 143 |
f.write(('%g ' * (len(line)-1)).rstrip() % line[1:] + '\n')
|
| 144 |
|
| 145 |
if save_img or view_img:
|
| 146 |
+
label = f'{names[int(cls)]} {conf:.2f} || Recommendation : {name_recommanded.lower()}'
|
| 147 |
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)
|
| 148 |
if view_img:
|
| 149 |
cv2.imshow(str(p), im0)
|
detect.py
CHANGED
|
@@ -13,9 +13,11 @@ from utils.general import check_img_size, check_requirements, check_imshow, non_
|
|
| 13 |
scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
|
| 14 |
from utils.plots import plot_one_box
|
| 15 |
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def detect(save_img=False):
|
|
|
|
| 19 |
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|
| 20 |
save_img = not opt.nosave and not source.endswith('.txt') # save inference images
|
| 21 |
webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
|
|
@@ -117,6 +119,8 @@ def detect(save_img=False):
|
|
| 117 |
|
| 118 |
# Write results
|
| 119 |
for *xyxy, conf, cls in reversed(det):
|
|
|
|
|
|
|
| 120 |
if save_txt: # Write to file
|
| 121 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
| 122 |
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
|
|
@@ -124,7 +128,7 @@ def detect(save_img=False):
|
|
| 124 |
f.write(('%g ' * len(line)).rstrip() % line + '\n')
|
| 125 |
|
| 126 |
if save_img or view_img: # Add bbox to image
|
| 127 |
-
label = f'{names[int(cls)]} {conf:.2f}'
|
| 128 |
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=1)
|
| 129 |
|
| 130 |
# Print time (inference + NMS)
|
|
|
|
| 13 |
scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
|
| 14 |
from utils.plots import plot_one_box
|
| 15 |
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
| 16 |
+
from recommendation import SimilarityRecommender
|
| 17 |
|
| 18 |
|
| 19 |
def detect(save_img=False):
|
| 20 |
+
recommender = SimilarityRecommender("./TopBrands.xlsx")
|
| 21 |
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|
| 22 |
save_img = not opt.nosave and not source.endswith('.txt') # save inference images
|
| 23 |
webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith(
|
|
|
|
| 119 |
|
| 120 |
# Write results
|
| 121 |
for *xyxy, conf, cls in reversed(det):
|
| 122 |
+
name_class = names[int(cls.item())]
|
| 123 |
+
name_recommanded = recommender.make_recommendation(name_class)
|
| 124 |
if save_txt: # Write to file
|
| 125 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
| 126 |
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
|
|
|
|
| 128 |
f.write(('%g ' * len(line)).rstrip() % line + '\n')
|
| 129 |
|
| 130 |
if save_img or view_img: # Add bbox to image
|
| 131 |
+
label = f'{names[int(cls)]} {conf:.2f} || Recommendation : {name_recommanded.lower()}'
|
| 132 |
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=1)
|
| 133 |
|
| 134 |
# Print time (inference + NMS)
|
hubconf.py
CHANGED
|
@@ -83,7 +83,7 @@ def yolov7(pretrained=True, channels=3, classes=80, autoshape=True):
|
|
| 83 |
|
| 84 |
|
| 85 |
if __name__ == '__main__':
|
| 86 |
-
model = custom(path_or_model='
|
| 87 |
# model = create(name='yolov7', pretrained=True, channels=3, classes=80, autoshape=True) # pretrained example
|
| 88 |
|
| 89 |
# Verify inference
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
if __name__ == '__main__':
|
| 86 |
+
model = custom(path_or_model='best_logo.pt') # custom example
|
| 87 |
# model = create(name='yolov7', pretrained=True, channels=3, classes=80, autoshape=True) # pretrained example
|
| 88 |
|
| 89 |
# Verify inference
|