in Education by
I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my full code: from __future__ import absolute_import, division, print_function import tensorflow as tf from tensorflow import keras import matplotlib.pyplot as plt fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] train_images = train_images / 255.0 train_labels = train_labels / 255.0 plt.figure(figsize=(10,10)) for i in range(25): plt.subplot(5,5,i+1) plt.xticks([]) plt.yticks([]) plt.grid(False) plt.imshow(train_images[i], cmap=plt.cm.binary) plt.xlabel(class_names[train_labels[i]]) plt.show() The issue is on this line: plt.xlabel(class_names[train_labels[i]]) TypeError: list indices must be integers or slices, not numpy.float64 No problem, change the numpy.float64 to int using .item() plt.xlabel(class_names[train_labels[i.item()]]) AttributeError: 'int' object has no attribute 'item' Was it an int in the first place? This is running on Python 3.7, with Tensorflow 1.13.1. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The error is because of the following python line: train_labels = train_labels / 255.0 Here you have divided by 255.0 to scale the values so that it reduces the computational time. This is called Normalization. You need to do normalization only for train_images but not for train_labels. So, remove that mentioned line above and it will work fine. You can register for this AI Course by Intellipaat that teaches Artificial Intelligence in TensorFlow with Instructor-led training, good projects, and case studies.

Related questions

0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am new to TensorFlow. While I am reading the existing documentation, I found the term tensor really confusing. ... types of tensors? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I have worked all the tutorials and searched for "load csv tensorflow" but just can't get the logic of it all. ... and test the net. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am trying to decompose a 3D matrix using python library scikit-tensor. I managed to decompose my Tensor ... the decomposed matrices? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to calculate precision and recall measures for multiclass multilabel classification, i.e. classification ... labels? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    Currently, I have Keras with TensorFlow and CUDA at the backend. But, I want to force Keras to use the ... are accessible via Keras. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I was looking at the docs of TensorFlow about tf.nn.conv2d here. But I can't understand what it does or ... it raised the question. Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Is Tensorflow similar to scikit learn's one hot encoder for processing of categorical data? Does using placeholder of ... very easy. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have noticed that in most models step parameter is used to indicate the no. of steps to run over data ... epochs? Data shuffling? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I recently started finding out deep learning & machine learning techniques, and I started sorting out frameworks ... machine learning. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am trying to understand the role of the Flatten function in Keras. Below is my code, which is a simple two ... flatten it? Thanks! Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a Python dictionary like the following: {u'2012-06-08': 388, u'2012-06-09': 388, u'2012-06-10 ... (my_dict,index=my_dict.keys()) Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    What is the role of Flatten in Keras. I am executing the code below and it's a two layered network. The ... output is already flat? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I started Tensorflow some days back and I understand that it is a visualization tool but is there any way to ... remote Ubuntu machine? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    In tensorflow API documentation here one keyword was there logits. What is logits? In most of the documents I went ... , name=None) Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...