I implore you to help me crack this nagging problem. I’ve been trying to gain insight into ML using keras 3.0.5 on tensorflow 2.16.1 on python 3.12 on Windows 8.1. To aid my understanding, I copied working sample codes from numerous contributors on various sites. But the codes wouldn’t run error-free on my computer. They keep bumping out with the following error:
Traceback (most recent call last):
File "C:\Users\amenzeosas\AppData\Local\Programs\Python\Python36-32\practice.py", line 69, in <module>
model = Sequential()
File "C:\Users\amenzeosas\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\models\model.py", line 144, in __new__
return super().__new__(cls)
File "C:\Users\amenzeosas\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\layers\layer.py", line 217, in __new__
obj = super().__new__(cls, *args, **kwargs)
File "C:\Users\amenzeosas\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\ops\operation.py", line 100, in __new__
flat_arg_values = tree.flatten(kwargs)
AttributeError: module 'tree' has no attribute 'flatten'
AN EXAMPLE CODE THAT TRIGGERS THE ERROR IS THE FOLLOWING: from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential()
layer_1 = Dense(16, input_shape=(8,8))
model.add(layer_1)
layer_2 = Flatten()
model.add(layer_2)
layer_2.input_shape (None, 8, 16)
layer_2.output_shape (None, 128)
A SECOND EXAMPLE IS THIS OTHER SIMPLE ONE:
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential() #Create a Sequential model
#Add layers to the model
model.add(Dense(64, activation='relu', input_shape=(10,)))
model.add(Dense(64, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
input_data = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]] #Sample input data
output = model.predict(input_data) #Predict the output using the model
print("Output:", output)
A THIRD EXAMPLE IS THIS EVEN SIMPLER ONE:
import tensorflow as tf
model = tf.keras.Sequential()
model.add(tf.keras.layers.Conv2D(64, 3, 3, input_shape=(3, 32, 32)))
model.output_shape
print ('Done')
In all three cases, the system reports the above error. And the error is usually triggered at the very first line of the code block. Please assist.
I ran each block of code. I was expecting the programs to execute successfully as they did for the Authors. But they kept crashing out with the error on my own system.