Home > other >  Tensorflow - model. Predict error for help
Tensorflow - model. Predict error for help

Time:11-23

# machine vision
 
The import tensorflow as tf
The from tensorflow import keras
Fashion_mnist=keras. Datasets. Fashion_mnist
(train_images train_labels), (test_images, test_labels)=fashion_mnist. Load_data ()

# data download
 Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 
32768/29515 [=================================] 0 s 15 us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] us 50-1319 - s/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
8192/5148 [===============================================] 0 s 10 us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] 43-191 - s us/step


# modeling
 model=keras. Sequential () 
Model. The add (keras. The layers. Flatten (input_shape=(28, 28)))
Model. The add (keras. The layers. Dense (128, activation=tf. Nn. Relu))
Model. The add (keras. The layers. Dense (10, activation=tf. Nn. Softmax))


# training
 train_images=train_images/255 
Model.com from running (optimizer=tf. Optimizers. Adam (), loss=tf. Losses. Sparse_categorical_crossentropy, metrics=[' accuracy '])
The model fit (train_images train_labels, epochs=10)

 
Epoch 1/10
1875/1875 [==============================] - 1 s 675 us/step - loss: 2.3029 - accuracy: 0.1014
Epoch 2/10
1875/1875 [==============================] - 1 s 647 us/step - loss: 2.3028 - accuracy: 0.0994
Epoch 3/10
1875/1875 [==============================] - 1 s 641 us/step - loss: 2.3028 - accuracy: 0.1011
Epoch 4/10
1875/1875 [==============================] - 1 s 644 us/step - loss: 2.3028 - accuracy: 0.0996
Epoch 5/10
1875/1875 [==============================] - 1 s 637 us/step - loss: 2.3027 - accuracy: 0.1017
Epoch 6/10
1875/1875 [==============================] - 1 s 642 us/step - loss: 2.3029 - accuracy: 0.0998
Epoch 7/10
1875/1875 [==============================] - 1 s 644 us/step - loss: 2.3028 - accuracy: 0.1017
Epoch 8/10
1875/1875 [==============================] - 1 s 652 us/step - loss: 2.3027 - accuracy: 0.1010
Epoch 9/10
1875/1875 [==============================] - 1 s 645 us/step - loss: 2.3027 - accuracy: 0.1014
Epoch 10/10
1875/1875 [==============================] - 1 s 644 us/step - loss: 2.3026 - accuracy: 0.1010


# training test
 test_images_scaled=test_images/255 
Model. The evaluate (test_images_scaled test_labels)

 
313/313 [==============================] 0 s 535 us/step - loss: 589.2147 - accuracy: 0.2129
[589.2147216796875, 0.21289999783039093]


# model test
 import numpy as np 
Np. Argmax (model predict (train_images [8]))


# for the wool was an error? Thought for ages
 
ValueError Traceback (the most recent call last)

- & gt; 1 model. Predict (test_images [8])

/opt/anaconda3/lib/python3.8/site - packages/tensorflow/python/keras/engine/training. Py in _method_wrapper (self, * args, * * kwargs)
128 raise ValueError (' {} is not supported in multi - worker mode. ". The format (
Method 129. __name__))
- & gt; 130 the return method (self, * args, * * kwargs)
131
132 return tf_decorator. Make_decorator (

/opt/anaconda3/lib/python3.8/site - packages/tensorflow/python/keras/engine/training. Py in predict (self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1597 for step in data_handler. Steps () :
1598 callbacks. On_predict_batch_begin (step)
- & gt; 1599 tmp_batch_outputs=predict_function (iterator)
1600 if data_handler. Should_sync:
1601 the context. Async_wait ()

/opt/anaconda3/lib/python3.8/site - packages/tensorflow/python/eager/def_function py in __call__ (self, * args, * * KWDS)
778 else:
779 the compiler="nonXla
"- & gt; 780 the result=self. _call (* args, * * KWDS)
781
782 new_tracing_count=self. _get_tracing_count ()

/opt/anaconda3/lib/python3.8/site - packages/tensorflow/python/eager/def_function py in _call (self, * args, * * KWDS)
812 # In this case we have not created the variables on the first call. So we can
813 # run the first trace but we should fail if the variables are created.
- & gt; Results 814=self. _stateful_fn (* args, * * KWDS)
815 if self. _created_variables:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related