A community member has associated this post with a similar question:
How do I fix TensorFlow/Keras error : "ValueError: Value returned by __array__ is not a NumPy array"

Only moderators can edit this content.

How to fix an error in tensorflow/keras for an exercise on creating a Convolutional Neural Networks

Sajad Hussain 5 Reputation points
2025-01-04T13:35:52.2766667+00:00

I'm following the Microsoft learning exercise and have the following problem.

I would appreciate assistance so that i can continue on with my exercises.

Note: I also had problems with a previous section exercise "Train a deep neural network model" for which i raised an assistance request and that issue is still open and i was asked to continue with the exercises, so i continued with the next section, now I'm surprised also this section is also giving me errors.

Here are the details of the error in this section/exercise:

milestone : Create and implement machine learning models (create machine learning models)

Train and evaluate deep learning models

Exercise - Train a convolutional neutral network

Perfomring exercise with Convolutional Neural Networks (Tensorflow).ipynb

Inside the note book I'm on step "Train the model"

The last Epoch 5/5 completes with the following "step - accuracy: 0.9950 - loss: 0.0336 - val_accuracy: 0.9972 - val_loss: 0.008"

The I ran the the code under section "View the loss history" and I get the following error:

"ValueError: x and y must have same first dimension, but have shapes (5,) and (3,)"

see below for the full error stack:

ValueError Traceback (most recent call last)

Cell In[12], line 8

  6 validation_loss = history.history["val_loss"]

  7 plt.plot(epoch_nums, training_loss)
----> 8 plt.plot(epoch_nums, validation_loss)

9 plt.xlabel('epoch')

10 plt.ylabel('loss')


   3786 @_copy_docstring_and_deprecators(Axes.plot)

   3787 def plot(

   3788     *args: float | ArrayLike | str,

   (...)

   3792     **kwargs,

   3793 ) -> list[Line2D]:

-> 3794     return gca().plot(

   3795         *args,

   3796         scalex=scalex,

   3797         scaley=scaley,

   3798         **({"data": data} if data is not None else {}),

   3799         **kwargs,

   3800     )

File /anaconda/envs/azureml_py38_PT_TF/lib/python3.10/site-packages/matplotlib/axes/_axes.py:1779, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)

   1536 """

   1537 Plot y versus x as lines and/or markers.

   1538 

   (...)

   1776 (``'green'``) or hex strings (``'#008000'``).

   1777 """

   1778 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)

-> 1779 lines = [*self._get_lines(self, *args, data=data, **kwargs)]

   1780 for line in lines:

   1781     self.add_line(line)

File /anaconda/envs/azureml_py38_PT_TF/lib/python3.10/site-packages/matplotlib/axes/_base.py:296, in _process_plot_var_args.__call__(self, axes, data, *args, **kwargs)

294 this += args[0],

295 args = args[1:]


297 axes, this, kwargs, ambiguous_fmt_datakey=ambiguous_fmt_datakey)


483 axes.yaxis.update_units(y)

485 if x.shape[0] != y.shape[0]:


487 f"have shapes {x.shape} and {y.shape}")

488 if x.ndim > 2 or y.ndim > 2:

489 raise ValueError(f"x and y can be no greater than 2D, but have "

490 f"shapes {x.shape} and {y.shape}")


 

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
40,817 questions
{count} votes