thinh-huynh-re commited on
Commit
dc332e5
·
1 Parent(s): 6dc33a4
Files changed (2) hide show
  1. .gitignore +2 -1
  2. run_opencv.py +10 -1
.gitignore CHANGED
@@ -3,4 +3,5 @@ env
3
  tmp/*
4
  !tmp/.gitkeep
5
  *.mp4
6
- .DS_Store
 
 
3
  tmp/*
4
  !tmp/.gitkeep
5
  *.mp4
6
+ .DS_Store
7
+ diary.json
run_opencv.py CHANGED
@@ -1,8 +1,8 @@
1
  import json
 
2
  from typing import List, Optional, Tuple
3
 
4
  import cv2
5
- import numpy as np
6
  import pandas as pd
7
  import torch
8
  from tap import Tap
@@ -50,6 +50,12 @@ class ActivityModel:
50
 
51
  self.load_json()
52
 
 
 
 
 
 
 
53
  def load_json(self):
54
  if args.id2label is not None:
55
  with open(args.id2label, encoding="utf-8") as f:
@@ -93,6 +99,7 @@ class ActivityModel:
93
  self.args.threshold is not None and confidence >= self.args.threshold
94
  ):
95
  img_container.frame_rate.label = f"{predicted_label}_{confidence:.2f}%"
 
96
 
97
  # logits = np.squeeze(logits)
98
  # logits = logits.squeeze().numpy()
@@ -167,6 +174,8 @@ def main(args: ArgParser):
167
  elif k == ord("r"):
168
  img_container.toggle_recording()
169
 
 
 
170
  # After the loop release the cap object
171
  camera.release()
172
  video_output.release()
 
1
  import json
2
+ from datetime import datetime
3
  from typing import List, Optional, Tuple
4
 
5
  import cv2
 
6
  import pandas as pd
7
  import torch
8
  from tap import Tap
 
50
 
51
  self.load_json()
52
 
53
+ self.diary: List[Tuple[str, str, float]] = [] # [time, activity, confidence]
54
+
55
+ def save_diary(self):
56
+ df = pd.DataFrame(self.diary, columns=["time", "activity", "confidence"])
57
+ df.to_csv("diary.csv")
58
+
59
  def load_json(self):
60
  if args.id2label is not None:
61
  with open(args.id2label, encoding="utf-8") as f:
 
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((str(datetime.now()), predicted_label, confidence))
103
 
104
  # logits = np.squeeze(logits)
105
  # logits = logits.squeeze().numpy()
 
174
  elif k == ord("r"):
175
  img_container.toggle_recording()
176
 
177
+ activity_model.save_diary()
178
+
179
  # After the loop release the cap object
180
  camera.release()
181
  video_output.release()