ANP-Granular / ParticleTracking

Library and GUI for tracking (rod-like) particles on camera images in 2D and 3D
https://particletracking.readthedocs.io/en/latest/
GNU General Public License v3.0
2 stars 2 forks source link

Index Error while detecting particles #91

Closed merrygoat closed 3 months ago

merrygoat commented 4 months ago

Describe the bug When running particle detection an error dialog appears with IndexError. This does not seem to stop the particle detection process. The error can be triggered repeatedly by scrolling through the images during a detection.

To Reproduce Load test image set. In detection tab, "load default model". Set particles to 25. Press detect button. After some particles have been detected, use the arrow keys to navigate through images. Error dialog is shown.

Additional context This is something to do with rod tracker attempting to display the overlay of the detected particles. I am not sure if it is caused by attempting to display an overlay while that image is being processed or attempting to display an overlay on an image immediately after it is processed.

The error dialog is confusing as you would expect a modal error dialog box to indicate that a process has failed - however detection continues in the background. I guess that this is because the dialog is coming from the gui thread rather than the detection thread.

If you can't address the underlying issue, I would suggest changing this error to a warning or info level message as it does not affect the process of detection.

Logs

[06/28 15:07:40] RodTracker.ui.loggerwidget INFO: (camera_0) (gp3) 25 image file(s) loaded from: ~\Documents\git\rod_tracking\RodTracker\src\RodTracker\resources\example_data\images\gp3
[06/28 15:07:48] RodTracker.ui.detection INFO: ~\AppData\Local\ANP-Granular\RodTracker\example_model.pt
[06/28 15:08:56] py.warnings WARNING: ~\Documents\git\rod_tracking\venv\Lib\site-packages\torch\nn\modules\module.py:1541: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ..\aten\src\ATen\native\TensorShape.cpp:3588.)
  return forward_call(*args, **kwargs)

[06/28 15:08:56] RodTracker.ui.loggerwidget INFO: (gp3, 500) Detected 8 rods.
[06/28 15:08:56] RodTracker ERROR: Uncaught exception:
Traceback (most recent call last):
  File "~\Documents\git\rod_tracking\RodTracker\src\RodTracker\ui\view3d.py", line 207, in update_rods
    np.linalg.norm(np.array((dxs[idx], dys[idx], dzs[idx])))
                             ~~~^^^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
[06/28 15:08:56] RodTracker ERROR: Uncaught exception:
Traceback (most recent call last):
  File "~\Documents\git\rod_tracking\RodTracker\src\RodTracker\ui\view3d.py", line 207, in update_rods
    np.linalg.norm(np.array((dxs[idx], dys[idx], dzs[idx])))
                             ~~~^^^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
[06/28 15:08:56] RodTracker.ui.reconstruction INFO: Insufficient data for plotting given. Skipping...
[06/28 15:08:56] RodTracker.ui.reconstruction INFO: Insufficient data for plotting given. Skipping...
[06/28 15:08:56] RodTracker.ui.reconstruction INFO: Insufficient data for plotting given. Skipping...
[06/28 15:09:08] RodTracker.backend.rod_data INFO: No 2D rod position data available for frame #501.
[06/28 15:09:08] RodTracker.ui.loggerwidget INFO: (gp3, 501) Detected 8 rods.
[06/28 15:09:08] RodTracker.ui.reconstruction INFO: Insufficient data for plotting given. Skipping...
[06/28 15:09:08] RodTracker.ui.reconstruction INFO: Insufficient data for plotting given. Skipping...
[06/28 15:09:09] RodTracker ERROR: Uncaught exception:
Traceback (most recent call last):
  File "~\Documents\git\rod_tracking\RodTracker\src\RodTracker\ui\view3d.py", line 207, in update_rods
    np.linalg.norm(np.array((dxs[idx], dys[idx], dzs[idx])))
                             ~~~^^^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
a-niem commented 3 months ago

From my testing, it looks like this occurs only when Expected particles is set to 1 during the detection process, which is also backed by your logs:

[06/28 15:08:56] RodTracker.ui.loggerwidget INFO: (gp3, 500) Detected 8 rods. ... [06/28 15:09:08] RodTracker.ui.loggerwidget INFO: (gp3, 501) Detected 8 rods.

From the error message, it seems, that a loss of dimension occurs during the extraction of 3D rod position for the 3D display, which then leads to the displayed indexing error.

merrygoat commented 3 months ago

Ah - that is what I did wrong. Even though 1 is probably not a sensible input value, that seems to be resolved now.