Skip to content

Commit 8c8be77

Browse files
author
Jeremy Delahanty
committed
Correct dtype bug, close #1
1 parent 9e285ed commit 8c8be77

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

dask_faces.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Adapted repository for mouse facial expression analysis from Dolensek et al 2020
22
# Written with the gracious help of John Kirkham, Josh Moore, and Martin Durant (Dask/Zarr Developers)
33
# ParticularMiner, Jeremy Delahanty May 2022
4-
4+
import sys
5+
import matplotlib.pyplot as plt
6+
import zarr
57
import numpy as np
68
import time
79
import warnings
@@ -158,7 +160,7 @@ def normalize_hog_desc_dims(tuple_):
158160

159161
program_start = time.perf_counter()
160162

161-
video_path = "movies/20211216_CSE014_plane1_-333.325.mp4"
163+
video_path = "movies/test_vid.mp4"
162164

163165
pims.ImageIOReader.class_priority = 100 # we set this very high in order to force dask's imread() to use this reader [via pims.open()]
164166

@@ -189,9 +191,19 @@ def normalize_hog_desc_dims(tuple_):
189191
# Descriptors: 2D histogram, several descriptors per chunk
190192
meta = np.array([[[]]])
191193

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
195207

196208
# Map the chunks of the grey_frames results onto the make_hogs() function.
197209
# Perform cropping, HOG calculations, and HOG image generation.
@@ -203,14 +215,6 @@ def normalize_hog_desc_dims(tuple_):
203215
kwargs=kwargs,
204216
)
205217

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-
214218
# Get the resulting images out of the returned tuple from my_hogs() chunks. Save that
215219
# as a dask array of images.
216220
hog_images = my_hogs.map_blocks(
@@ -254,13 +258,13 @@ def normalize_hog_desc_dims(tuple_):
254258
# Tell dask to perform computations via processes and not threads. Using threads yields severe
255259
# performance decreases! I don't know specifically why it struggles so much...
256260
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")
259263

260264
print("Data written to zarr! Hooray!")
261265

262266
# On a powerful machine (64 Cores, Intel Xeon, 256GB RAM), approx. 44k frames complete in
263267
# 8 minutes!
264268
program_end = time.perf_counter() - program_start
265269

266-
print(f"PROGRAM RUNTIME: {program_end}")
270+
print(f"PROGRAM RUNTIME: {program_end}")

0 commit comments

Comments
 (0)