Feature extraction and classification

I’m using unet encoder to extract features followed by a LSTM for classification. I defined the encoder and the classifier but unable to connect it.

X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.2, random_state=42)

I need the features to be extracted and displayed and then use those features in calling the lstm.

Encoder:
def encoder(input_img):
#output_filters=1
dropout = 0.1

n1 = 64
filters = [n1, n1 * 2, n1 * 4, n1 * 8, n1 * 16]

print(“Original Shape”, input_img.shape)
print(“------Encoder------------”)
x0_0 = conv2d_block(input_img, filters[0])

p1 = MaxPooling2D((2, 2))(x0_0 )
p1 = Dropout(dropout)(p1)
x1_0 = conv2d_block(p1, filters[1])
p2 = MaxPooling2D((2, 2))(x1_0)
p2 = Dropout(dropout)(p2)

x2_0 = conv2d_block(p2, filters[2])
p3 = MaxPooling2D((2, 2))(x2_0)
p3 = Dropout(dropout)(p3)

x3_0 = conv2d_block(p3, filters[3])

p4 = MaxPooling2D((2, 2))(x3_0)
p4 = Dropout(dropout)(p4)

x4_0 = conv2d_block(p4, filters[4])
return x0_0,x1_0,x2_0,x3_0,x4_0

function call:
input_img = Input((256, 256, 1), name=‘img’)
x0_0,x1_0,x2_0,x3_0,x4_0 = encoder(input_img)

Here i need the x4_0 features by giving my dataset as input. Dataset has 2 labels. then use these features to train_test_split and in the model.fit(features,labels)

Hi @Swetha_Sarma,

Sorry for the delay in response.
I recommend to follow this way to connect u-net encoder with LSTM for feature extraction and classfication.First, define the U-Net encoder to extract features from input images and reshape the feature maps for LSTM input (e.g., [samples, timesteps, features]). Lastly, split the data into training and test sets, then define and train the LSTM for classification. Here is a sample implementation gist for your reference.

Thank You.