From e3f9c28ee1f7192c8c882af9625005fdfd417f69 Mon Sep 17 00:00:00 2001 From: keceli Date: Mon, 21 Sep 2020 04:39:20 -0500 Subject: [PATCH] Fixes for issues #22 and #23 (#24) * 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 --- ffn/training/inputs.py | 2 +- ffn/utils/bounding_box.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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(coord, volname): 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) diff --git a/ffn/utils/bounding_box.py b/ffn/utils/bounding_box.py index f3e38f5..a2d1835 100644 --- a/ffn/utils/bounding_box.py +++ b/ffn/utils/bounding_box.py @@ -31,6 +31,7 @@ from . import bounding_box_pb2 from . import geom_utils +from typing import Optional class BoundingBox(object): """BoundingBox built on Numpy, interoperable with bounding_box_pb2."""