Reputation: 89
I am a new to tensorflow, I am trying to build a simple neural network. But every time I get close, there are a list of errors stopping me. I followed tutorials and documentations and kept most of the code and changed only things I need to.
Here is my code:
###
# Import
###
import tensorflow as tf
import pandas as pd
from tensorflow import keras
###
# Loading Data
###
# Training Data
# path of the training data
train_data_path = "C:/Users/User/Desktop/Machine_Learning/Neural_Network/addition_train_data.csv"
train_data = pd.read_csv(train_data_path) # loads the data using pandas
# Evalution Data
# path of the evalution data
eval_data_path = "C:/Users/User/Desktop/Machine_Learning/Neural_Network/addition_eval_data.csv"
eval_data = pd.read_csv(eval_data_path) # loads the data using pandas (again)
# Target Columns
train_target = train_data.pop("Sum")
eval_target = eval_data.pop("Sum")
###
# Creating the Model
###
model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(35, 2)))
model.add(keras.layers.Lambda(
lambda x: tf.expand_dims(model.output, axis=-1)))
model.add(keras.layers.Dense(10, activation="tanh"))
model.add(keras.layers.Dense(1, activation="tanh"))
###
# Compiling the Model
###
model.compile(
optimizer='adam',
loss='mean_absolute_error',
metrics=['accuracy']
)
###
# Training the Model
###
model.fit(
eval_data, eval_target, epochs=10
)
Console Output:
2020-05-25 10:53:35.491127: 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-05-25 10:53:35.493137: 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.
2020-05-25 10:53:37.162913: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library nvcuda.dll
2020-05-25 10:53:37.194951: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with
properties:
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.755GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s
2020-05-25 10:53:37.200604: 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-05-25 10:53:37.206365: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library cublas64_10.dll
2020-05-25 10:53:37.212086: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library cufft64_10.dll
2020-05-25 10:53:37.214531: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library curand64_10.dll
2020-05-25 10:53:37.219340: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library cusolver64_10.dll
2020-05-25 10:53:37.224932: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library cusparse64_10.dll
2020-05-25 10:53:37.233220: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully
opened dynamic library cudnn64_7.dll
2020-05-25 10:53:37.235711: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some
GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would
like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup
the required libraries for your platform.
Skipping registering GPU devices...
2020-05-25 10:53:37.241553: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports
instructions that this TensorFlow binary was not compiled to use: AVX2
2020-05-25 10:53:37.249295: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1d9e0a5c5f0
initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-25 10:53:37.252889: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device
(0): Host, Default Version
2020-05-25 10:53:37.255179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect
StreamExecutor with strength 1 edge matrix:
2020-05-25 10:53:37.258151: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
Epoch 1/10
WARNING:tensorflow:Model was constructed with shape (None, 35, 2) for input Tensor("flatten_input:0",
shape=(None, 35, 2), dtype=float32), but it was called on an input with incompatible shape (None, 2).
WARNING:tensorflow:Model was constructed with shape (None, 35, 2) for input Tensor("flatten_input:0",
shape=(None, 35, 2), dtype=float32), but it was called on an input with incompatible shape (None, 2).
Traceback (most recent call last):
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py", line 60, in
quick_execute
inputs, attrs, num_outputs)
TypeError: An op outside of the function building code is being passed
a "Graph" tensor. It is possible to have Graph tensors
leak out of the function building context by including a
tf.init_scope in your function building code.
For example, the following function will fail:
@tf.function
def has_init_scope():
my_constant = tf.constant(1.)
with tf.init_scope():
added = my_constant * 2
The graph tensor has name: dense_1/Identity:0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "addition.py", line 58, in <module>
eval_data, eval_target, epochs=10
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 66, in
_method_wrapper
return method(self, *args, **kwargs)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 848, in
fit
tmp_logs = train_function(iterator)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 580, in
__call__
result = self._call(*args, **kwds)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 644, in
_call
return self._stateless_fn(*args, **kwds)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 2420, in
__call__
return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1665, in
_filtered_call
self.captured_inputs)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1746, in
_call_flat
ctx, args, cancellation_manager=cancellation_manager))
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 598, in call
ctx=ctx)
File "C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py", line 74, in
quick_execute
"tensors, but found {}".format(keras_symbolic_tensors))
tensorflow.python.eager.core._SymbolicException: Inputs to eager execution function cannot be Keras
symbolic tensors, but found [<tf.Tensor 'dense_1/Identity:0' shape=(None, 70, 1) dtype=float32>]
Any help, tips, and advice is greatly appreciated.
Upvotes: 1
Views: 466
Reputation: 3278
I think the issue is with the Lambda
layer that was taking model.ouput
.
based on your eval_data
and eval_target
, I updated the model. So, please check the following model.
model = tf.keras.Sequential()
# model.add(tf.keras.layers.Flatten(input_shape=(2,)))
# model.add(tf.keras.layers.Lambda(lambda x: tf.expand_dims(model.output, axis=-1)))
model.add(tf.keras.layers.Dense(10, activation="tanh",input_shape=(2,)))
model.add(tf.keras.layers.Dense(1, activation="tanh"))
model.summary()
Model: "sequential_2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_4 (Dense) (None, 10) 30
_________________________________________________________________
dense_5 (Dense) (None, 1) 11
=================================================================
Total params: 41
Trainable params: 41
Non-trainable params: 0
_________________________________________________________________
Upvotes: 1