File size: 2,016 Bytes
1ffc9bc
 
19668e0
 
1ffc9bc
03b376b
87b0e10
 
 
 
 
8d90842
 
 
 
 
 
 
 
 
 
 
 
 
d0e9e07
8d90842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21c057a
8d90842
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
license: mit
datasets:
- Verah/Curculionidae-alpha
---
A simple retinanet_R_101_FPN model to detect (bounding box) and classify insects between these four species:
- Animalia Arthropoda Insecta Coleoptera Curculionidae Cactophagus spinolae
- Animalia Arthropoda Insecta Coleoptera Curculionidae Cyrtepistomus castaneus
- Animalia Arthropoda Insecta Coleoptera Curculionidae Diaprepes abbreviatus
- Animalia Arthropoda Insecta Coleoptera Curculionidae Larinus carlinae

![Training and Validation Loss](loss.png)


![Training and Validation Loss](example.png)

inference example, requires detectron2
```python
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
from detectron2 import model_zoo
import cv2

# edit all of these
image = cv2.imread("../../Datasets/inaturalist2021/custom2/val/imgs/01.jpg")
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file('COCO-Detection/retinanet_R_101_FPN_3x.yaml'))
cfg.MODEL.WEIGHTS = './out3/model_0002899.pth'
cfg.MODEL.DEVICE = 'cuda:0'

predictor = DefaultPredictor(cfg)
outputs = predictor(image)

threshold = 0.5
classes = ["Curculionidae Cactophagus spinolae", "Curculionidae Cyrtepistomus castaneus", "Curculionidae Diaprepes abbreviatus", "Curculionidae Larinus carlinae"]
# Display predictions
preds = outputs["instances"].pred_classes.tolist()
scores = outputs["instances"].scores.tolist()
bboxes = outputs["instances"].pred_boxes

print(preds,scores,bboxes)

for j, bbox in enumerate(bboxes):
    bbox = bbox.tolist()

    score = scores[j]
    pred = preds[j]
    if pred > 3:
        continue
    text = classes[pred]+ " "+ str(score)[:5]

    if score > threshold:
        x1, y1, x2, y2 = [int(i) for i in bbox]

        cv2.rectangle(image, (x1, y1), (x2, y2), (0, 0, 255), 1)
        if y1 < 5:
            y1 = 10
        image = cv2.putText(image, text, (0, y1), cv2.FONT_HERSHEY_SIMPLEX ,  
                   0.5, (0, 0, 255) , 1, cv2.LINE_AA) 
        print(text)

cv2.imshow('image', image)
cv2.waitKey(0)
```