I'm working on Visualizing Filters of a CNN using TensorFlow - Guided Project in Ccoursera.
I encountered the error
Invalid shape (1, 96, 96, 3) for image data
when trying to call the plot_image function. I defined the size of the image error screenshot as (96,96,3) but it takes as (1,96,96,3)
def create_image():
im = tf.random.uniform((96,96,3),minval=0.5,maxval=0.5)
return im
def plot_image(image,title ='random'):
image =image - tf.math.reduce_min(image),
image =image / tf.math.reduce_max(image)
plt.imshow(image)
plt.xticks([])
plt.yticks([])
plt.title(title)
plt.imshow(image)
plt.show()
image = create_image()
plot_image(image)
I tried using
image_data_channels_first = np.random.rand(3, 96, 96)
image_data_channels_last = np.moveaxis(image_data_channels_first, 0, -1)
I also tried the Squeeze method, but it didn't work. I'm encountering the same error when calling the function.