I'm following this tutorial on implementing a simple neural network, that would read data from a csv file. Here is the data stored in games.csv
white_pawns, black_pawns, white_queens, black_queens,result
3, 4, 1, 1, -1
3, 5, 1, 2, -1
6, 4, 0, 0, 1
2, 2, 3, 1, 1
5, 2, 0, 3, -1
10, 10, 0, 0, 1
8, 10, 0, 1, -1
And here is the code created following the instructions. My columns are already numeric so I skipped that part of the tutorial.
import tensorflow as tf
def pack(features, label):
return tf.stack(list(features.values()), axis=-1), label
labelColumn = 'result'
labels = [-1, 1]
train_file_path = "C:/games.csv"
games_train = tf.data.experimental.make_csv_dataset(
train_file_path,
batch_size=5,
label_name=labelColumn,
na_value="?",
num_epochs=1,
ignore_errors=True
)
packed_dataset = games_train.map(pack)
train_data = packed_dataset.shuffle(500)
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(4,)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='mse',
metrics=['accuracy'])
model.fit(train_data, epochs=1)
It seems that the data is read correctly, but when trying to call model.fit(train_data, epochs=1) I get an error:
2/Unknown - 2s 1s/step - loss: 1.0507 - accuracy: 0.0000e+002020-02-02 15:14:00.577149: W tensorflow/core/common_runtime/base_collective_executor.cc:216] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
2/2 [==============================] - 2s 1s/step - loss: 1.0507 - accuracy: 0.0000e+00
Exception ignored in: <function _RandomSeedGeneratorDeleter.__del__ at 0x000001FAF02041F8>
Traceback (most recent call last):
File "C:\Program Files\Anaconda\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py", line 3009, in __del__
AttributeError: 'NoneType' object has no attribute 'device'
Exception ignored in: <function _RandomSeedGeneratorDeleter.__del__ at 0x000001FAF02041F8>
Traceback (most recent call last):
File "C:\Program Files\Anaconda\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py", line 3009, in __del__
AttributeError: 'NoneType' object has no attribute 'device'
Exception ignored in: <function _RandomSeedGeneratorDeleter.__del__ at 0x000001FAF02041F8>
Traceback (most recent call last):
File "C:\Program Files\Anaconda\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py", line 3009, in __del__
AttributeError: 'NoneType' object has no attribute 'device'
What am I doing wrong here and how can I fix it?
What version of Tensorflow are you using? Tf2.0 this might not be an issue.
It seems that it might be a bug in TF, to rectify, you can look at editing the tensorflow code in site-packages;
In dataset_ops.py, at the top of the file add
import tensorflow as tf
and then on line 2944 and 3009 replace:
with ops.device(self._device):
with
with tf.device(self._device):
Refer to the bug report here;
https://github.com/tensorflow/tensorflow/issues/35326
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With