apple / tensorflow_macos

TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.
Other
3.66k stars 308 forks source link

Check failed: outputs_[index].tensor == nullptr #280

Open scan opened 3 years ago

scan commented 3 years ago

I am trying to learn TensorFlow following the book AI and Machine Learning for Coders, but now I'm stuck at the chapter on the MNIST_Fashion because I get the above error. This is my program:

import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Flatten, Dense
from tensorflow.python.compiler.mlcompute import mlcompute

mlcompute.set_mlc_device(device_name='cpu')

data = tf.keras.datasets.fashion_mnist

(training_images, training_labels), (test_images, test_labels) = data.load_data()

training_images = training_images / 255.0
test_image = test_images / 255.0

l0 = Flatten(input_shape=[28, 28])
l1 = Dense(128, activation=tf.nn.relu)
l2 = Dense(10, activation=tf.nn.softmax)

model = Sequential([l0, l1, l2])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

model.fit(training_images, training_labels, epochs=5)

model.evaluate(test_images, test_labels)

classifications = model.predict(test_images)
print(classifications[0])
print(test_labels[0])

And this is the output:

2021-06-06 19:57:20.921316: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
2021-06-06 19:57:20.921635: W tensorflow/core/platform/profile_utils/cpu_utils.cc:126] Failed to get CPU frequency: 0 Hz
Epoch 1/5
1875/1875 [==============================] - 1s 350us/step - loss: 0.6136 - accuracy: 0.7874
Epoch 2/5
1875/1875 [==============================] - 1s 341us/step - loss: 0.3859 - accuracy: 0.8597
Epoch 3/5
1875/1875 [==============================] - 1s 347us/step - loss: 0.3398 - accuracy: 0.8751
Epoch 4/5
1875/1875 [==============================] - 1s 344us/step - loss: 0.3139 - accuracy: 0.8844
Epoch 5/5
1875/1875 [==============================] - 1s 341us/step - loss: 0.2997 - accuracy: 0.8898
313/313 [==============================] - 0s 240us/step - loss: 52.6934 - accuracy: 0.8649
2021-06-06 19:57:24.459642: I tensorflow/compiler/tf2mlcompute/kernels/mlc_subgraph_op.cc:326] Compute: Failed in processing TensorFlow graph sequential/MLCSubgraphOp_2_0 with frame_id = 0 and iter_id = 0 with error: Internal: ExecuteMLCInferenceGraph: Failed to execute MLC inference graph. (error will be reported 5 times unless TF_MLC_LOGGING=1).
2021-06-06 19:57:24.460286: F tensorflow/core/framework/op_kernel.cc:983] Check failed: outputs_[index].tensor == nullptr (0x144211c70 vs. nullptr)

I have entirely re-installed the conda environment as per this guide and used all the current versions. After reading some error reports on here, I have dropped numpy down to 1.19.5 using conda install numpy=1.19.5, but I get the same error.

I'm not really a python guy so I'm trying to figure this out, but now I am entirely stuck. Using miniforge and current conda --version reports conda 4.10.1. Also, using Pythong 3.8.10.