So I recently wanted to experiment with Tensorflow and Keras again after some time. I have tried it in the past but I only scratched the surface before I got distracted and tried other things. Now, as I said, I wanted to try it out again so I just made sure I had the newest versions of Tensorflow and Keras using pip and then copied an example from the official Tensorflow website. This is the code:
# TensorFlow and tf.kerasimport tensorflow as tf# Helper librariesimport numpy as npimport matplotlib.pyplot as pltfashion_mnist = tf.keras.datasets.fashion_mnist(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()train_images, test_images = train_images/255, test_images/255class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat','Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']model = tf.keras.Sequential([ tf.keras.layers.Input(shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dense(10)])model.compile(optimizer="adam", loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics = ["accuracy"])model.fit(train_images, train_labels, epochs=10)Now when I run the code I get this error:
Traceback (most recent call last): File "C:\Users\me\AppData\Local\Programs\Python\Python311\Tensorflow\example.py", line 21, in <module> tf.keras.layers.Input(shape=(28, 28)), File "C:\Users\me\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\layers\core\input_layer.py", line 143, in Input layer = InputLayer( File "C:\Users\me\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\layers\layer.py", line 216, in __new__ obj = super().__new__(cls, *args, **kwargs) File "C:\Users\me\AppData\Local\Programs\Python\Python311\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'I am not new to programming or python either so I also tried installing different versions of Tensorflow and also using pip to upgrade the "tree" module. I also tried just replacing the function (yes a bad practice I know) using something like
tree.flatten = lambda kwargs: kwargs
but nothing has seemed to resolve the issue. I would be glad if someone knew what the problem is and could help me out.