I'm having a problem with my Keras model, in the .compile() I use accuracy, loss, precision, recall and AUC, but also I need f1_score, due to Keras doesn´t include f1_score, I tried to calculate by myself but I get this error NameError: name 'model' is not defined
, here's my code:
def residual_network_1d(input_shape):
n_feature_maps = 64
input_layer = keras.layers.Input(input_shape)
# BLOCK 1
conv_x = keras.layers.Conv1D(filters=n_feature_maps, kernel_size=8, padding='same')(input_layer)
...
# FINAL
gap_layer = keras.layers.GlobalAveragePooling1D()(output_block_3)
output_layer = keras.layers.Dense(27, activation='softmax')(gap_layer)
model = keras.models.Model(inputs=input_layer, outputs=output_layer)
return model
residual_network_1d_model=residual_network_1d(input_shape = (5000,1))
def f1_score(y_test,y_pred):
import numpy as np
from sklearn.metrics import f1_score
y_test = np.argmax(folds[0][1],axis=0)
y_pred1 = model.predict(x=pc.generate_validation_data(ecg_filenames,y,folds[0][1])[0])
y_pred = np.argmax(y_pred1, axis=1)
my_f1_score=f1_score(y_test, y_pred , average="macro")
return my_f1_score
residual_network_1d_model.compile(loss=tf.keras.losses.BinaryCrossentropy(), optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), metrics=[tf.keras.metrics.BinaryAccuracy(
name='accuracy', dtype=None, threshold=0.5),tf.keras.metrics.Recall(name='Recall'),tf.keras.metrics.Precision(name='Precision'),f1_score,
tf.keras.metrics.AUC(
num_thresholds=200,
curve="ROC",
summation_method="interpolation",
name="AUC",
dtype=None,
thresholds=None,
multi_label=True,
label_weights=None,
)])
Why say model is not defined
if I load my model previously?