TypeError: __array__() takes 1 positional argument but 2 were given after installing Tensorflow 2.5 in venv at Windows 10

  numpy, python, tensorflow, tensorflow2.0

currently I am following Tensorflow website (https://www.tensorflow.org/install/pip) to install latest Tensorflow 2.5 in my Windows 10 machine. I have installed python3.7, CUDA 11 and latest cudnn. Then I created the venv as mentioned in Tensorflow website and I use the command

pip install tensorflow

to install Tensorflow. However, after installed, when I tried to run the model.fit function, it triggered the error as follows:

File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginetraining.py", line 1147, in fit
    steps_per_execution=self._steps_per_execution)
  File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginedata_adapter.py", line 1364, in get_data_handler
    return DataHandler(*args, **kwargs)
  File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginedata_adapter.py", line 1166, in __init__
    model=model)
  File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginedata_adapter.py", line 939, in __init__
    **kwargs)
  File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginedata_adapter.py", line 809, in __init__
    peek, x = self._peek_and_restore(x)
  File "C:Usersxxxxxxlibsite-packagestensorflowpythonkerasenginedata_adapter.py", line 943, in _peek_and_restore
    return x[0], x
  File "C:UsersxxxAppDataLocalProgramsPythonPython37libsite-packageskeras_preprocessingimageiterator.py", line 65, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)
  File "C:UsersxxxAppDataLocalProgramsPythonPython37libsite-packageskeras_preprocessingimageiterator.py", line 231, in _get_batches_of_transformed_samples
    x = img_to_array(img, data_format=self.data_format)
  File "C:UsersxxxAppDataLocalProgramsPythonPython37libsite-packageskeras_preprocessingimageutils.py", line 309, in img_to_array
    x = np.asarray(img, dtype=dtype)
  File "C:Usersxxxxxxlibsite-packagesnumpycore_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: __array__() takes 1 positional argument but 2 were given

Basically the code I am running is working well at other machine but I not sure why it will trigger this error at this new machine. I have repeatedly to try, even use Anaconda with pip to install the Tensorflow, but same error still happened. I am sincerely appreciate if anyone can give me some guidance to solve this.

Thank you very much

Source: Python Questions

One Reply to “TypeError: __array__() takes 1 positional argument but 2 were given after installing Tensorflow 2.5 in venv at Windows 10”

LEAVE A COMMENT