Whereas if you specify an `Input`, the model gets built continuously as you are adding layers:
model = keras.Sequential()
model.add(keras.Input(shape=(16,)))
model.add(keras.layers.Dense(8))len(model.weights)
# Returns "2"
I am not familiar with this course but it says you have more layers than supposed too, maybe you have put too many or maybe you can omit the input layer and build the model. Try to to read the Tensorflow link I attached above!
I don’t see anything wrong with your code for the model or for model.compile().
However, It does appear that you have combine the code into one cell, which should each be in separate cells. The code you show should be in three separate cells.
Modifying the notebook like this is not recommended. The reason is that every cell has metadata which you cannot see, and that is used by Jupyter to control how your code is used.
I recommend you delete your notebook and start over with a fresh copy. Then only modify the parts of the notebook that are identified by the “START CODE HERE” banner.
Please don’t delete any lines of comments - those are included for a reason.
Hi TMosh:
According to advice, I copy the code in a new notebook.
The codes are in three cell, I run them one by one.
It is ok when I run it until the code "model_test(model, classes, X_train.shape[1]) " which showed that
"ValueError: The layer Complex has never been called and thus has no defined input.
"
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.activations import relu,linear
from tensorflow.keras.losses import SparseCategoricalCrossentropy
from tensorflow.keras.optimizers import Adam
from public_tests_a1 import *
from assigment_utils import *
# Generate and split data set
X, y, centers, classes, std = gen_blobs()
# split the data. Large CV population for demonstration
X_train, X_, y_train, y_ = train_test_split(X,y,test_size=0.50, random_state=1)
X_cv, X_test, y_cv, y_test = train_test_split(X_,y_,test_size=0.20, random_state=1)
print("X_train.shape:", X_train.shape, "X_cv.shape:", X_cv.shape, "X_test.shape:", X_test.shape)
I recommended that you get a fresh copy of the notebook and start over, paying particular attention to following the instructions and only modifying the portions of the notebook that are marked.