vanvalenlab / deepcell-tracking

Track cells and build cell lineages
Other
29 stars 6 forks source link

`CellTracker.track_cells` crashes if there is a frame with no objects. #71

Open willgraf opened 3 years ago

willgraf commented 3 years ago

I've encountered an issue where track_cells crashes unexpectedly with this error:

Traceback (most recent call last):
  File "/train.py", line 324, in <module>
    track_length=args.track_length)
  File "/train.py", line 242, in evaluate
    tracker.track_cells()
  File "/usr/local/lib/python3.6/dist-packages/deepcell_tracking/tracking.py", line 639, in track_cells
    self._track_frame(frame)
  File "/usr/local/lib/python3.6/dist-packages/deepcell_tracking/tracking.py", line 623, in _track_frame
    cost_matrix, predictions = self._get_cost_matrix(frame)
  File "/usr/local/lib/python3.6/dist-packages/deepcell_tracking/tracking.py", line 420, in _get_cost_matrix
    ], axis=0)
  File "<__array_function__ internals>", line 6, in stack
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py", line 423, in stack
    raise ValueError('need at least one array to stack')
ValueError: need at least one array to stack

Digging into the error, I find that in _get_cost_matrix, we compare the current cell features with the future cell features, stacking together each feature into a single array. The error indicates that we are trying to stack an empty list, which means that future_feature is empty.

https://github.com/vanvalenlab/deepcell-tracking/blob/526b65b9aff539e340bac0aad148c762cf5eadba/deepcell_tracking/tracking.py#L414-L420

future_feature is initialized by _get_frame_features, which populates a dictionary with features for every cell in the frame. I think the root cause of this bug is that there are no objects in the frame, and so future_feature is returned as an empty dictionary.

https://github.com/vanvalenlab/deepcell-tracking/blob/526b65b9aff539e340bac0aad148c762cf5eadba/deepcell_tracking/tracking.py#L269-L273

It would also be prudent make sure that _fetch_tracked_features (which creates the current_feature dictionary that also gets stacked together) is also robust to empty frames.

willgraf commented 3 years ago

The Track object should also be investigated for this empty frame issue.