def data():
xTrain, xVal, yTrain, yVal = train_test_split(X_data, Y_Labels, test_size=0.1, random_state=42) # checked
return xTrain, yTrain, xVal, yVal
# Define the model (CNN) for single source localization
input_shape = xTrain.shape[1:]
kern_size1 = 3
kern_size2 = 2
model = Sequential() # kernel_regularizer=l1(0.00001),
model.add(Conv2D(256, kernel_size=(kern_size1,kern_size1), activation=None, input_shape=input_shape, name="Conv2D_1",padding="valid", strides=(2,2)))
model.add(BatchNormalization(trainable=True))
model.add(ReLU())
model.add(Conv2D(256, kernel_size=(kern_size2,kern_size2), activation=None,name="Conv2D_2", padding="valid"))
model.add(BatchNormalization(trainable=True))
model.add(ReLU())
model.add(Conv2D(256, kernel_size=(kern_size2,kern_size2), activation=None,name="Conv2D_3", padding="valid"))
model.add(BatchNormalization(trainable=True))
model.add(ReLU())
model.add(Flatten())
model.add(Dense(4096, activation="relu",name="Dense_Layer1"))
model.add(Dropout(0.2,name="Dropout1"))
model.add(Dense(2048, activation="relu",name="Dense_Layer2"))
model.add(Dropout(0.2,name="Dropout2"))
model.add(Dense(1024, activation="relu",name="Dense_Layer3"))
model.add(Dropout(0.2,name="Dropout3"))
model.add(Dense(DNN_outp, activation="sigmoid", kernel_initializer=glorot_normal(seed=None),name="Classif_Layer"))
model.summary()
This is the code. I define the xTrain but it gives me an error at line ----> [2] input_shape = xTrain.shape[1:] saying NameError: name 'xTrain' is not defined. Why does this happen?
CodePudding user response:
You have to either remove the function data()
and only keep xTrain, xVal, yTrain, yVal = train_test_split(X_data, Y_Labels, test_size=0.1, random_state=42)
or use input_shape = data()[0].shape[1:]
.
This happens because your data()
function is returning a list of lists instead of separate variables.