npc0 commited on
Commit
904b5dd
β€’
1 Parent(s): 6f5895c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -7,15 +7,15 @@ from transformers import CLIPProcessor, CLIPModel
7
  model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
8
  processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
9
 
10
- # # load model
11
- # model = yolov5.load('keremberke/yolov5m-license-plate')
12
 
13
- # # set model parameters
14
- # model.conf = 0.5 # NMS confidence threshold
15
- # model.iou = 0.25 # NMS IoU threshold
16
- # model.agnostic = False # NMS class-agnostic
17
- # model.multi_label = False # NMS multiple labels per box
18
- # model.max_det = 1000 # maximum number of detections per image
19
 
20
  def license_plate_detect(img):
21
  results = model(img, size=640)
@@ -62,23 +62,26 @@ def check_solarplant_installed_by_image(image, output_label=False):
62
  return zero_shot_class_labels[probs.argmax().item()]
63
  return probs.argmax().item() == 0
64
 
65
- def check_solarplant_broken(image):
66
  zero_shot_class_labels = ["white broken solar panel",
67
  "normal black solar panel grids"]
68
  probs = zero_shot_classification(image, zero_shot_class_labels)
69
  idx = probs.argmax().item()
70
- return zero_shot_class_labels[idx][1-idx]
 
 
71
 
72
 
73
  def greet(img):
74
  print(type(img))
75
- # lns = read_license_number(img)
76
- lns = ['1','2','3']
77
  if len(lns):
 
78
  # return (seg,
79
  return ("θ»Šη‰ŒοΌš " + '; '.join(lns) + "\n\n" \
80
- + "ι‘žεž‹οΌš "+ check_solarplant_installed_by_image(img, True) + "\n\n" \
81
- + "η‹€ζ…‹οΌš" + check_solarplant_broken(img))
 
82
  return (img, "η©Ίεœ°γ€‚γ€‚γ€‚")
83
 
84
 
 
7
  model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
8
  processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
9
 
10
+ # load model
11
+ model = yolov5.load('keremberke/yolov5m-license-plate')
12
 
13
+ # set model parameters
14
+ model.conf = 0.5 # NMS confidence threshold
15
+ model.iou = 0.25 # NMS IoU threshold
16
+ model.agnostic = False # NMS class-agnostic
17
+ model.multi_label = False # NMS multiple labels per box
18
+ model.max_det = 1000 # maximum number of detections per image
19
 
20
  def license_plate_detect(img):
21
  results = model(img, size=640)
 
62
  return zero_shot_class_labels[probs.argmax().item()]
63
  return probs.argmax().item() == 0
64
 
65
+ def check_solarplant_broken(image, output_label=False):
66
  zero_shot_class_labels = ["white broken solar panel",
67
  "normal black solar panel grids"]
68
  probs = zero_shot_classification(image, zero_shot_class_labels)
69
  idx = probs.argmax().item()
70
+ if output_label:
71
+ return zero_shot_class_labels[idx].split(" ")[1-idx]
72
+ return idx == 0
73
 
74
 
75
  def greet(img):
76
  print(type(img))
77
+ lns = read_license_number(img)
 
78
  if len(lns):
79
+ planttype = check_solarplant_installed_by_image(img, True)
80
  # return (seg,
81
  return ("θ»Šη‰ŒοΌš " + '; '.join(lns) + "\n\n" \
82
+ + "ι‘žεž‹οΌš "+ planttype + "\n\n" \
83
+ + "η‹€ζ…‹οΌš" + (check_solarplant_broken(img, True)
84
+ if 'with' in planttype else 'normal'))
85
  return (img, "η©Ίεœ°γ€‚γ€‚γ€‚")
86
 
87