Skip to main content
. 2024 Jun 1;14(11):1174. doi: 10.3390/diagnostics14111174
Algorithm 1: Creating and Training the Hybrid Segmentation-Classification Model
Require: Input Shape = (256, 256, 3)
   1: Define Segmentation Model
   2: inputs ← Input(input_shape)
   3: conv1 ← Conv2D(32, (3, 3), activation=`relu’, padding=`same’)(inputs)
   4: pool1 ← MaxPooling2D(pool_size=(2, 2))(conv1)
   5: up1 ← UpSampling2D(size=(2, 2))(pool1)
   6: decoded ← Conv2D(3, (3, 3), activation=`sigmoid’, padding=`same’)(up1)
   7: segmentation_model ← Model(inputs, decoded, name=`segmentation_model’)
   8: Define Classification Model
   9: inputs ← Input(input_shape)
 10: conv1 ← Conv2D(16, (3, 3), activation=`relu’)(inputs)
 11: pool1 ← MaxPooling2D(pool_size=(2, 2))(conv1)
 12: conv2 ← Conv2D(32, (3, 3), activation=`relu’)(pool1)
 13: pool2 ← MaxPooling2D(pool_size=(2, 2))(conv2)
 14: conv3 ← Conv2D(64, (3, 3), activation=`relu’)(pool2)
 15: pool3 ← MaxPooling2D(pool_size=(2, 2))(conv3)
 16: flatten ← Flatten()(pool3)
 17: dense1 ← Dense(256, activation=`relu’)(flatten)
 18: output ← Dense(1, activation=`sigmoid’)(dense1)
 19: Combine Segmentation and Classification Models
 20: input_tensor ← Input(input_shape)
 21: segmentation_model ← create_segmentation_model()
 22: segmentation_output ← segmentation_model(input_tensor)
 23: classification_model ← create_classification_model()
 24: classification_output ← classification_model(segmentation_output)
 25: hybrid_model ← Model(inputs=input_tensor, outputs=classification_output, name=`hybrid_model’)
 26: Compile and Train the Hybrid Model
 27: hybrid_model.compile(optimizer=`adam’, loss=`binary_crossentropy’, metrics=[`acc’])
 28: logdir=`logs’
 29: hist ← hybrid_model.fit(train, epochs=25, validation_data=val, callbacks=[tensorboard_callback])