Skip to content

Commit 0851db3

Browse files
authored
Merge pull request #30 from pyronear/poses-occlusion-masks
adapt the sending of alerts to the concept of poses
2 parents a6d6d8f + b3f4ef1 commit 0851db3

6 files changed

Lines changed: 970 additions & 15 deletions

File tree

containers/init_script/init_script.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###### TODO REFACTOR : use the init scripts which are in the test_update_pi directory
1+
#  TODO REFACTOR : use the init scripts which are in the test_update_pi directory
22

33
#!/usr/bin/env python
44

@@ -72,6 +72,7 @@ def write_json_file(file_path, data):
7272
organizations = pd.read_csv(f"data/csv/API_DATA{sub_path} - organizations.csv")
7373
cameras = pd.read_csv(f"data/csv/API_DATA{sub_path} - cameras.csv")
7474
cameras = cameras.fillna("")
75+
poses = pd.read_csv(f"data/csv/API_DATA{sub_path} - poses.csv")
7576

7677
for orga in organizations.itertuples(index=False):
7778
logging.info(f"saving orga : {orga.name}")
@@ -131,6 +132,16 @@ def write_json_file(file_path, data):
131132
write_json_file(credentials_path, data)
132133
write_json_file(credentials_path_etl, data_wildfire)
133134

135+
logging.info("creating poses")
136+
for pose in poses.itertuples(index=False):
137+
payload = {
138+
"camera_id": pose.camera_id,
139+
"azimuth": pose.azimuth,
140+
"patrol_id": pose.patrol_id,
141+
}
142+
api_request("post", f"{api_url}/poses/", superuser_auth, payload)
143+
144+
134145
# Load environment variables from .env file
135146
# load_dotenv()
136147

containers/notebooks/app/send_real_alerts.ipynb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
"metadata": {},
140140
"outputs": [],
141141
"source": [
142+
"send_alert_from_cam_ids = [2, 4, 5, 14] # select cameras\n",
143+
"\n",
142144
"sequances_folders = glob.glob(f\"{SAMPLE_PATH}/*\")\n",
143145
"\n",
144146
"for camera_id in send_alert_from_cam_ids:\n",
@@ -151,17 +153,20 @@
151153
" imgs.sort()\n",
152154
" preds = glob.glob(f\"{sequances_folder}/labels_predictions/*\")\n",
153155
" preds.sort()\n",
154-
" \n",
155-
" cam_center_azimuth = random.randint(0,360)\n",
156-
" print(f\"Sending alerts from camera {camera_id} at azimuth {cam_center_azimuth}\")\n",
156+
"\n",
157+
" cam_poses = camera_client.get_current_poses().json()\n",
158+
" # pick a random pose id\n",
159+
" pose_id = random.choice(cam_poses)['id']\n",
160+
"\n",
161+
" print(f\"Sending alerts from camera {camera_id} at (pose_id={pose_id})\")\n",
157162
" for img_file, pred_file in zip(imgs, preds):\n",
158163
" \n",
159164
" stream = io.BytesIO()\n",
160165
" im = Image.open(img_file)\n",
161166
" im.save(stream, format=\"JPEG\", quality=80)\n",
162167
"\n",
163168
" bboxes = read_pred_file(pred_file)\n",
164-
" response = camera_client.create_detection(stream.getvalue(), cam_center_azimuth, bboxes)\n",
169+
" response = camera_client.create_detection(stream.getvalue(), bboxes, pose_id=pose_id)\n",
165170
" # Force a KeyError if the request failed\n",
166171
" \n",
167172
" response.json()[\"id\"]"
@@ -193,7 +198,7 @@
193198
"source": [
194199
"SEQUENCES_DIR_PATH = \"../data/alert_samples/single_sequences/*\"\n",
195200
"sequences_directories = glob.glob(SEQUENCES_DIR_PATH)\n",
196-
"CAM_MAPPING = {22:13, 42:7, 59:5, 14:11, 43:8, 79:14, 13:10, 11:15, 59:1, 60:2, 15:12, 12:9, 10:16, 41:2, 65:8}\n",
201+
"CAM_MAPPING = {22: 13, 42: 7, 59: 5, 14: 11, 43: 8, 79: 14, 13: 10, 11: 15, 60: 2, 15: 12, 12: 9, 10: 16, 41: 2, 65: 8}\n",
197202
"\n",
198203
"for seq_path in sequences_directories:\n",
199204
" \n",
@@ -211,9 +216,12 @@
211216
" preds = glob.glob(f\"{seq_path}/labels_predictions/*\")\n",
212217
" preds.sort()\n",
213218
"\n",
214-
" cam_center_azimuth = random.randint(0,360)\n",
219+
" cam_poses = camera_client.get_current_poses().json()\n",
220+
" # pick a random pose id\n",
221+
" pose_id = random.choice(cam_poses)['id']\n",
222+
"\n",
215223
" \n",
216-
" print(f\"Sending alerts from camera {camera_id} at azimuth {cam_center_azimuth}\")\n",
224+
" print(f\"Sending alerts from camera {camera_id} at (pose_id={pose_id})\")\n",
217225
" for img_file, pred_file in zip(imgs, preds):\n",
218226
" \n",
219227
" stream = io.BytesIO()\n",
@@ -223,9 +231,9 @@
223231
" #bboxes = read_pred_file(pred_file)\n",
224232
" with open(pred_file, 'r', encoding='utf-8') as file:\n",
225233
" bboxes = ast.literal_eval(file.read())\n",
226-
" \n",
227234
" #bboxes = np.loadtxt(pred_file, ndmin=2)\n",
228-
" response = camera_client.create_detection(stream.getvalue(), cam_center_azimuth, bboxes)\n",
235+
" response = camera_client.create_detection(stream.getvalue(), bboxes, pose_id=pose_id)\n",
236+
"\n",
229237
" # Force a KeyError if the request failed\n",
230238
" time.sleep(0.5)\n",
231239
" response.json()[\"id\"]"
@@ -352,7 +360,7 @@
352360
"name": "python",
353361
"nbconvert_exporter": "python",
354362
"pygments_lexer": "ipython3",
355-
"version": "3.13.7"
363+
"version": "3.11.14"
356364
}
357365
},
358366
"nbformat": 4,

0 commit comments

Comments
 (0)