Skip to content

Issue on some function in Mango_detection.ipynb #1

@WisarutBholsithi

Description

@WisarutBholsithi

Hi Sumit,
After I copy your /Mango_detection.ipynb to be used in the jupyter notebook which I used tensorflow version 2.18, I have got the error on the line "plt.imshow(image_gen.random_transform(Dis_leaf_img))" due to the issue with function ImageDataGenerator function which has become deprecated in Tensorflow 2.9 as mentioned in ImageDataGenerator() is deprecated in Tensorflow 2.9 and I'm using Tensorflow 2.18 which is for my python3.11 which is the python base for my jupyter notebook.

The depreciation of ImageDataGenerator() has caused the following error when I tried to plot the image create by applying random_transform function of image_gen to Dis_leaf_img image variable.

image_gen = ImageDataGenerator(rotation_range=20, # rotate the image 20 degrees
                               width_shift_range=0.10, # Shift the pic width by a max of 5%
                               height_shift_range=0.10, # Shift the pic height by a max of 5%
                               rescale=1/255, # Rescale the image by normalzing it.
                               shear_range=0.1, # Shear means cutting away part of the image (max 10%)
                               zoom_range=0.01, # Zoom in by 10% max
                               horizontal_flip=True, # Allow horizontal flipping
                               fill_mode='nearest' # Fill in missing pixels with the nearest filled value
                              )
RandomTransformImage = image_gen.random_transform(Dis_leaf_img)
plt.imshow(RandomTransformImage)

Here is the error message

ModuleNotFoundError Traceback (most recent call last)
Cell In[31], line 1
----> 1 RandomTransformImage = image_gen.random_transform(Dis_leaf_img)
2 plt.imshow(RandomTransformImage)

File /opt/conda/lib/python3.11/site-packages/keras/src/legacy/preprocessing/image.py:1460, in ImageDataGenerator.random_transform(self, x, seed)
1450 """Applies a random transformation to an image.
1451
1452 Args:
(...)
1457 A randomly transformed version of the input (same shape).
1458 """
1459 params = self.get_random_transform(x.shape, seed)
-> 1460 return self.apply_transform(x, params)

File /opt/conda/lib/python3.11/site-packages/keras/src/legacy/preprocessing/image.py:1413, in ImageDataGenerator.apply_transform(self, x, transform_parameters)
1410 img_col_axis = self.col_axis - 1
1411 img_channel_axis = self.channel_axis - 1
-> 1413 x = apply_affine_transform(
1414 x,
1415 transform_parameters.get("theta", 0),
1416 transform_parameters.get("tx", 0),
1417 transform_parameters.get("ty", 0),
1418 transform_parameters.get("shear", 0),
1419 transform_parameters.get("zx", 1),
1420 transform_parameters.get("zy", 1),
1421 row_axis=img_row_axis,
1422 col_axis=img_col_axis,
1423 channel_axis=img_channel_axis,
1424 fill_mode=self.fill_mode,
1425 cval=self.cval,
1426 order=self.interpolation_order,
1427 )
1429 if transform_parameters.get("channel_shift_intensity") is not None:
1430 x = apply_channel_shift(
1431 x,
1432 transform_parameters["channel_shift_intensity"],
1433 img_channel_axis,
1434 )

File /opt/conda/lib/python3.11/site-packages/keras/src/legacy/preprocessing/image.py:1879, in apply_affine_transform(x, theta, tx, ty, shear, zx, zy, row_axis, col_axis, channel_axis, fill_mode, cval, order)
1876 final_affine_matrix = transform_matrix[:2, :2]
1877 final_offset = transform_matrix[:2, 2]
-> 1879 channel_images = [
1880 scipy.ndimage.interpolation.affine_transform(
1881 x_channel,
1882 final_affine_matrix,
1883 final_offset,
1884 order=order,
1885 mode=fill_mode,
1886 cval=cval,
1887 )
1888 for x_channel in x
1889 ]
1890 x = np.stack(channel_images, axis=0)
1891 x = np.rollaxis(x, 0, channel_axis + 1)

File /opt/conda/lib/python3.11/site-packages/keras/src/legacy/preprocessing/image.py:1880, in (.0)
1876 final_affine_matrix = transform_matrix[:2, :2]
1877 final_offset = transform_matrix[:2, 2]
1879 channel_images = [
-> 1880 scipy.ndimage.interpolation.affine_transform(
1881 x_channel,
1882 final_affine_matrix,
1883 final_offset,
1884 order=order,
1885 mode=fill_mode,
1886 cval=cval,
1887 )
1888 for x_channel in x
1889 ]
1890 x = np.stack(channel_images, axis=0)
1891 x = np.rollaxis(x, 0, channel_axis + 1)

File /opt/conda/lib/python3.11/site-packages/keras/src/utils/module_utils.py:36, in LazyModule.getattr(self, name)
34 if self.module is None:
35 self.initialize()
---> 36 return getattr(self.module, name)

File /opt/conda/lib/python3.11/site-packages/scipy/init.py:134, in getattr(name)
132 def getattr(name):
133 if name in submodules:
--> 134 return _importlib.import_module(f'scipy.{name}')
135 else:
136 try:

File /opt/conda/lib/python3.11/importlib/init.py:126, in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File :1204, in _gcd_import(name, package, level)

File :1176, in find_and_load(name, import)

File :1147, in find_and_load_unlocked(name, import)

File :690, in _load_unlocked(spec)

File :940, in exec_module(self, module)

File :241, in _call_with_frames_removed(f, *args, **kwds)

File /opt/conda/lib/python3.11/site-packages/scipy/ndimage/init.py:152
1 """
2 =========================================================
3 Multidimensional image processing (:mod:scipy.ndimage)
(...)
119
120 """
122 # Copyright (C) 2003-2005 Peter J. Verveer
123 #
124 # Redistribution and use in source and binary forms, with or without
(...)
149 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
150 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--> 152 from ._filters import *
153 from ._fourier import *
154 from ._interpolation import *

File /opt/conda/lib/python3.11/site-packages/scipy/ndimage/_filters.py:37
34 import numpy as np
35 import operator
---> 37 from scipy._lib._util import normalize_axis_index
38 from . import _ni_support
39 from . import _nd_image

File /opt/conda/lib/python3.11/site-packages/scipy/_lib/_util.py:18
10 from typing import (
11 Optional,
12 Union,
13 TYPE_CHECKING,
14 TypeVar,
15 )
17 import numpy as np
---> 18 from scipy._lib._array_api import array_namespace, is_numpy, size as xp_size
21 AxisError: type[Exception]
22 ComplexWarning: type[Warning]

File /opt/conda/lib/python3.11/site-packages/scipy/_lib/_array_api.py:21
18 import numpy.typing as npt
20 from scipy._lib import array_api_compat
---> 21 from scipy._lib.array_api_compat import (
22 is_array_api_obj,
23 size,
24 numpy as np_compat,
25 device
26 )
28 all = ['array_namespace', '_asarray', 'size', 'device']
31 # To enable array API and strict array-like input validation

File /opt/conda/lib/python3.11/site-packages/scipy/_lib/array_api_compat/numpy/init.py:1
----> 1 from numpy import * # noqa: F403
3 # from numpy import * doesn't overwrite these builtin names
4 from numpy import abs, max, min, round # noqa: F401

File /opt/conda/lib/python3.11/site-packages/numpy/init.py:367, in getattr(attr)
365 raise AssertionError()
366 except AssertionError:
--> 367 msg = ("The current Numpy installation ({!r}) fails to "
368 "pass simple sanity checks. This can be caused for example "
369 "by incorrect BLAS library being linked in, or by mixing "
370 "package managers (pip, conda, apt, ...). Search closed "
371 "numpy issues for similar problems.")
372 raise RuntimeError(msg.format(file)) from None

ModuleNotFoundError: No module named 'numpy.rec'

How can I modified the code to replace ImageDataGenerator() with some better alternative?

Hope to get the answer soon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions