Spaces:
Runtime error
Runtime error
thinh-huynh-re
commited on
Commit
•
e00e6d6
1
Parent(s):
a3844a2
Update
Browse files- .gitignore +2 -1
- run_opencv.py +12 -4
.gitignore
CHANGED
@@ -4,4 +4,5 @@ tmp/*
|
|
4 |
!tmp/.gitkeep
|
5 |
*.mp4
|
6 |
.DS_Store
|
7 |
-
diary.csv
|
|
|
|
4 |
!tmp/.gitkeep
|
5 |
*.mp4
|
6 |
.DS_Store
|
7 |
+
diary.csv
|
8 |
+
diary.xlsx
|
run_opencv.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import json
|
2 |
from datetime import datetime
|
|
|
3 |
from typing import List, Optional, Tuple
|
4 |
|
5 |
import cv2
|
@@ -50,11 +51,16 @@ class ActivityModel:
|
|
50 |
|
51 |
self.load_json()
|
52 |
|
53 |
-
self.diary: List[
|
|
|
|
|
54 |
|
55 |
def save_diary(self):
|
56 |
-
df = pd.DataFrame(
|
|
|
|
|
57 |
df.to_csv("diary.csv")
|
|
|
58 |
|
59 |
def load_json(self):
|
60 |
if args.id2label is not None:
|
@@ -93,13 +99,15 @@ class ActivityModel:
|
|
93 |
return
|
94 |
predicted_label = self.model.config.id2label[max_index]
|
95 |
|
96 |
-
confidence = logits[0][max_index]
|
97 |
|
98 |
if (self.args.threshold is None) or (
|
99 |
self.args.threshold is not None and confidence >= self.args.threshold
|
100 |
):
|
101 |
img_container.frame_rate.label = f"{predicted_label}_{confidence:.2f}%"
|
102 |
-
self.diary.append(
|
|
|
|
|
103 |
|
104 |
# logits = np.squeeze(logits)
|
105 |
# logits = logits.squeeze().numpy()
|
|
|
1 |
import json
|
2 |
from datetime import datetime
|
3 |
+
from time import time
|
4 |
from typing import List, Optional, Tuple
|
5 |
|
6 |
import cv2
|
|
|
51 |
|
52 |
self.load_json()
|
53 |
|
54 |
+
self.diary: List[
|
55 |
+
Tuple[str, int, str, float]
|
56 |
+
] = [] # [time, activity, confidence]
|
57 |
|
58 |
def save_diary(self):
|
59 |
+
df = pd.DataFrame(
|
60 |
+
self.diary, columns=["time", "timestamp", "activity", "confidence"]
|
61 |
+
)
|
62 |
df.to_csv("diary.csv")
|
63 |
+
df.to_excel("diary.xlsx")
|
64 |
|
65 |
def load_json(self):
|
66 |
if args.id2label is not None:
|
|
|
99 |
return
|
100 |
predicted_label = self.model.config.id2label[max_index]
|
101 |
|
102 |
+
confidence = logits[0][max_index].item()
|
103 |
|
104 |
if (self.args.threshold is None) or (
|
105 |
self.args.threshold is not None and confidence >= self.args.threshold
|
106 |
):
|
107 |
img_container.frame_rate.label = f"{predicted_label}_{confidence:.2f}%"
|
108 |
+
self.diary.append(
|
109 |
+
(str(datetime.now()), int(time()), predicted_label, confidence)
|
110 |
+
)
|
111 |
|
112 |
# logits = np.squeeze(logits)
|
113 |
# logits = logits.squeeze().numpy()
|