0

I am building a neural network with keras and tensorfrolw as backend. it has 3 inputs from 0 to 9 and 3 outputs from 0 to 9. The data is served in a numpy array lie this: [ ['1' '4' '0'] ['6' '2' '1'] ...].

I am new to deep learning and this is one of my first neural networks so i am lost and have no idea what is causing this error.

I am aware that i probably need to change the optimizer, loss, metrics and probably more attributes, if anyone has any insights on that please share.

model = keras.Sequential([
    keras.layers.Flatten(3, input_shape=(3, 3)),
    keras.layers.Dense(9, activation="relu"),
    keras.layers.Dense(9, activation="relu"),
    keras.layers.Dense(3, activation="relu")
])
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.fit(training_input, training_output, epochs=5)

When i run this program i get this error:

Traceback (most recent call last):
  File "C:/Users/---/---/---/---/---/---/---/main.py", line 15, in <module>
    keras.layers.Flatten(3, input_shape=(3, 3)),
  File "C:\Users\---\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\layers\core.py", line 571, in __init__
    self.data_format = conv_utils.normalize_data_format(data_format)
  File "C:\Users\---\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\utils\conv_utils.py", line 191, in normalize_data_format
    data_format = value.lower()
AttributeError: 'int' object has no attribute 'lower' \

2 Answers 2

1

I had provided an argument to the flatten layer when I shouldn't have. Busted:

import tensorflow.keras.layers as l

h = i = l.Input(shape=(10, 5))
h = l.Flatten(50)(h) # don't do this!
o = l.Dense(50)(h)
model = keras.Model(inputs=i, outputs=o)
model.compile(optimizer='adam', loss='mse')

With no argument specified the model compiles:

import tensorflow.keras.layers as l

h = i = l.Input(shape=(10, 5))
h = l.Flatten()(h) # do this!
o = l.Dense(50)(h)
model = keras.Model(inputs=i, outputs=o)
model.compile(optimizer='adam', loss='mse')
Sign up to request clarification or add additional context in comments.

Comments

0

Please check Keras Documentation for using Flatten() layer. You are misusing the Flatten. I suggest you to do the reshaping of your data before your model and feed forward into the model.

2 Comments

Thanks dude. I should have written keras.layers.Dense(3, input_shape=(3,)),
Hope your problem resolves. Seems like your optimizers, loss or metrics is not problematic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.