Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AxisError with numpy 1.18 #23

Open
keceli opened this issue Jun 26, 2020 · 0 comments
Open

AxisError with numpy 1.18 #23

keceli opened this issue Jun 26, 2020 · 0 comments

Comments

@keceli
Copy link
Contributor

keceli commented Jun 26, 2020

I got the following error, when I tried to run FFN training with numpy 1.18:
numpy.AxisError: axis 4 is out of bounds for array of dimension 4

Looks like it is due to a recent change in numpy.expand_dims. See https://numpy.org/doc/stable/reference/generated/numpy.expand_dims.html.

Here is a patch to fix the error:

diff --git a/ffn/training/inputs.py b/ffn/training/inputs.py
index d1b5c31..b9a9c7e 100644
--- a/ffn/training/inputs.py
+++ b/ffn/training/inputs.py
@@ -152,7 +152,7 @@ def load_from_numpylike(coordinates, volume_names, shape, volume_map,
     if data.ndim == 4:
       data = np.rollaxis(data, 0, start=4)
     else:
-      data = np.expand_dims(data, 4)
+      data = np.expand_dims(data, data.ndim)

     # Add flat batch dim and return.
     data = np.expand_dims(data, 0)
--
mjanusz pushed a commit that referenced this issue Sep 21, 2020
* Fix for AxisError with numpy 1.18

FFN fails with
`numpy.AxisError: axis 4 is out of bounds for array of dimension 4`

when numpy 1.18 is used.

See the 1.18 note for numpy.expand_dims at
https://numpy.org/doc/stable/reference/generated/numpy.expand_dims.html
```
axis int or tuple of ints
Position in the expanded axes where the new axis (or axes) is placed.

Deprecated since version 1.13.0: Passing an axis where axis > a.ndim will be treated as axis == a.ndim, and passing axis < -a.ndim - 1 will be treated as axis == 0. This behavior is deprecated.

Changed in version 1.18.0: A tuple of axes is now supported. Out of range axes as described above are now forbidden and raise an AxisError.
```

* Fix import error

Training fails since Optional was not imported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant