1
1
# Adapted repository for mouse facial expression analysis from Dolensek et al 2020
2
2
# Written with the gracious help of John Kirkham, Josh Moore, and Martin Durant (Dask/Zarr Developers)
3
3
# ParticularMiner, Jeremy Delahanty May 2022
4
-
4
+ import sys
5
+ import matplotlib .pyplot as plt
6
+ import zarr
5
7
import numpy as np
6
8
import time
7
9
import warnings
@@ -158,7 +160,7 @@ def normalize_hog_desc_dims(tuple_):
158
160
159
161
program_start = time .perf_counter ()
160
162
161
- video_path = "movies/20211216_CSE014_plane1_-333.325 .mp4"
163
+ video_path = "movies/test_vid .mp4"
162
164
163
165
pims .ImageIOReader .class_priority = 100 # we set this very high in order to force dask's imread() to use this reader [via pims.open()]
164
166
@@ -189,9 +191,19 @@ def normalize_hog_desc_dims(tuple_):
189
191
# Descriptors: 2D histogram, several descriptors per chunk
190
192
meta = np .array ([[[]]])
191
193
192
- # Provide the datatype of the grayscaled images for writing dask arrays
193
- # later.
194
- dtype = grey_frames .dtype
194
+ # first determine the output hog shapes from the first grey-scaled image so that
195
+ # we can use them for all other outputs:
196
+ first_hog_descr , first_hog_image = make_hogs (
197
+ grey_frames [:1 , ...].compute (),
198
+ coords ,
199
+ kwargs
200
+ )
201
+
202
+ # Provide the datatype of the hog images for writing dask arrays
203
+ # later. If you use the datatype of the grey_frames, it will send all your
204
+ # data to zero! Be sure to use the datatype that the function you're operating
205
+ # with gives you unless it's safe to change it later!
206
+ dtype = first_hog_image .dtype
195
207
196
208
# Map the chunks of the grey_frames results onto the make_hogs() function.
197
209
# Perform cropping, HOG calculations, and HOG image generation.
@@ -203,14 +215,6 @@ def normalize_hog_desc_dims(tuple_):
203
215
kwargs = kwargs ,
204
216
)
205
217
206
- # first determine the output hog shapes from the first grey-scaled image so that
207
- # we can use them for all other images:
208
- first_hog_descr , first_hog_image = make_hogs (
209
- grey_frames [:1 , ...].compute (),
210
- coords ,
211
- kwargs
212
- )
213
-
214
218
# Get the resulting images out of the returned tuple from my_hogs() chunks. Save that
215
219
# as a dask array of images.
216
220
hog_images = my_hogs .map_blocks (
@@ -254,13 +258,13 @@ def normalize_hog_desc_dims(tuple_):
254
258
# Tell dask to perform computations via processes and not threads. Using threads yields severe
255
259
# performance decreases! I don't know specifically why it struggles so much...
256
260
with dask .config .set (scheduler = 'processes' ):
257
- da .to_zarr (hog_images , "/scratch/snlkt_facial_expression/hogs /data.zarr" , component = "images" )
258
- da .to_zarr (hog_descriptors , "/scratch/snlkt_facial_expression/hogs /data.zarr" , component = "descriptors" )
261
+ da .to_zarr (hog_images , "/scratch/snlkt_facial_expression/test /data.zarr" , component = "images" )
262
+ da .to_zarr (hog_descriptors , "/scratch/snlkt_facial_expression/test /data.zarr" , component = "descriptors" )
259
263
260
264
print ("Data written to zarr! Hooray!" )
261
265
262
266
# On a powerful machine (64 Cores, Intel Xeon, 256GB RAM), approx. 44k frames complete in
263
267
# 8 minutes!
264
268
program_end = time .perf_counter () - program_start
265
269
266
- print (f"PROGRAM RUNTIME: { program_end } " )
270
+ print (f"PROGRAM RUNTIME: { program_end } " )
0 commit comments