I normally use CPU-based TensorFlow 2.4 on my university's cluster; however, I have wanted to get it running locally on my personal machines' RTX GPUs.
I followed a couple guides and got TensorFlow 2.10 installed in an anaconda3 (Python 3.9) environment (https://geekflare.com/install-tensorflow-on-windows-and-linux/).
import sys
import sklearn
import tensorflow as tf
from tensorflow import keras
import numpy as np
import os
import matplotlib as mpl
import matplotlib.pyplot as plt
model = keras.models.Sequential()
model.add(keras.layers.Dense(1024, activation="relu"))
model.add(keras.layers.Dense(1024, activation="relu"))
model.add(keras.layers.Dense(1024, activation="relu"))
model.add(keras.layers.Dense(1024, activation="relu"))
model.add(keras.layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
history = model.fit(x_train, y_train, epochs=30,validation_data=(x_valid, y_valid))
This is a bit of code that I used for my binary classification on the cluster. It works just fine on the cluster in Jupyter. However, when I run it locally in Jupyter, I get this error:
Epoch 1/30
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 history = model.fit(x_train, y_train, epochs=30)
File ~\anaconda3\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File ~\AppData\Local\Temp\__autograph_generated_fileepgl5krt.py:15, in outer_factory.<locals>.inner_factory.<locals>.tf__train_function(iterator)
13 try:
14 do_return = True
---> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False
ValueError: in user code:
File "C:\Users\Name\anaconda3\lib\site-packages\keras\engine\training.py", line 1160, in train_function *
return step_function(self, iterator)
File "C:\Users\Name\anaconda3\lib\site-packages\keras\engine\training.py", line 1146, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\Users\Name\anaconda3\lib\site-packages\keras\engine\training.py", line 1135, in run_step **
outputs = model.train_step(data)
File "C:\Users\Name\anaconda3\lib\site-packages\keras\engine\training.py", line 993, in train_step
y_pred = self(x, training=True)
File "C:\Users\Name\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\Name\anaconda3\lib\site-packages\keras\engine\input_spec.py", line 250, in assert_input_compatibility
raise ValueError(
ValueError: Exception encountered when calling layer "sequential" " f"(type Sequential).
Input 0 of layer "dense" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)
Call arguments received by layer "sequential" " f"(type Sequential):
• inputs=tf.Tensor(shape=(None,), dtype=float32)
• training=True
• mask=None
Can someone help me figure out what is going wrong?