I am getting acquainted with Tensorflow keras in Python.
I try to train a very simple network, with a simple dataset created by myself. I am trying to follow the lines of the tutorial in the official tf website:
https://www.tensorflow.org/tutorials/keras/basic_regression
In particular, I have the following code:
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow import layers
# Generate data
NumElems = 1000
NumDims = 2
TrainSize = int(0.6 * NumElems)
print(TrainSize)
x = np.random.rand(NumDims,NumElems)*2 - 1
y = sum(x**2)
x_training = x[:, :TrainSize]
y_training = y[:TrainSize]
x_test = x[:, TrainSize:]
y_test = y[TrainSize:]
# Build the model
NH1 = 10 #Number of hidden nodes on first layer
NH2 = 10 #Number of hidden nodes on second layer
model = keras.Sequential()
model.add(layers.Dense(NH1, activation='relu'))
model.add(layers.Dense(NH2, activation='relu'))
model.add(layers.Dense(1))
#Compile the model
optimizer = tf.keras.optimizers.RMSprop(0.001)
model.compile(loss='mse', optimizer=optimizer, metrics=['mae', 'mse'])
#Train the model
model.fit(x_training, y_training, epochs=10, batch_size = 50)
It works well excepted for the last line, which generates the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/giuseppe/TF_Regression.py", line 38, in <module>
model.fit(x_training, y_training, epochs=10, batch_size = 50)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1536, in fit
validation_split=validation_split)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 992, in _standardize_user_data
class_weight, batch_size)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1032, in _standardize_weights
self._set_inputs(x)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/training/checkpointable/base.py", line 474, in _method_wrapper
method(self, *args, **kwargs)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1242, in _set_inputs
self.build(input_shape=input_shape)
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/sequential.py", line 221, in build
with ops.name_scope(layer._name_scope()):
File "/home/giuseppe/venv/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 151, in _name_scope
return self._current_scope.original_name_scope
AttributeError: 'NoneType' object has no attribute 'original_name_scope'
I have no clue what it is about and how to fix it. Could someone please help me?
I thank you in advance. My best regards, Giuseppe