1
I am making the code of a video lesson of Tensorflow but my code for more q is equal does not give the same result
Everything that appears in the terminal:
Windows PowerShell
Copyright (C) Microsoft Corporation. Todos os direitos reservados.
Experimente a nova plataforma cruzada PowerShell https://aka.ms/pscore6
PS D:\Curso IA> & "D:/Program Files (x86)/Microsoft Visual Studio/Shared/Python37_64/python.exe" "d:/Curso IA/aulaTensorFlow.py"
2020-06-04 16:07:37.196750: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-06-04 16:07:37.207068: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "d:/Curso IA/aulaTensorFlow.py", line 16, in <module>
keras.layers.Flatten(input_shape=(28.28)),
File "C:\Users\lucas\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\layers\core.py", line 630, in __init__
super(Flatten, self).__init__(**kwargs)
File "C:\Users\lucas\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\training\tracking\base.py", line 456, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\lucas\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\base_layer.py", line 373, in __init__
batch_input_shape = (batch_size,) + tuple(kwargs['input_shape'])
TypeError: 'float' object is not iterable
Code:
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
banco_de_imagens = keras.datasets.fashion_mnist
(train_images, trains_labels), (test_images, test_labels) = banco_de_imagens.load_data()
class_names = ['t_shirt','trouser','pullover','dress','coat','sandal','shirt','sneaker','bag','boot']
train_images = train_images / 255.0
test_images = test_images / 255.0
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28.28)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metric=['accuracy'])
model.fit(train_images, trains_labels, epochs=5)
predictions = model.predict(test_images)
print(predictions[0])
I don’t know the tensorflow, but according to the error message you may have accidentally exchanged the comma for the floating point in the middle of the numbers
28
or you don’t know that you need to use a comma after the first element to inform you that you want to create a tuple. Try calling the function again by passing as argument(28, 28)
or(28.28, )
.– JeanExtreme002
Thanks I managed to figure out the problem should be 28,28 and not 28.28 (the keys of my comma and dot keyboard do not differ) besides that the version of Keras I am using changed a little compared to the tutorial I am following (put Metric[old] instead of Metrics[current])
– Lucas