Hello !
I want to adapt a model from segmentation_model_pytorch to predict a continuoiuys value, regression.
So i have image and a label (in range 0 to 100)
what should i do ? i am a beginner and i did a dummy model:
class CustomModel(nn.Module):
def __init__(self, cfg, weight=None):
super().__init__()
self.cfg = cfg
self.encoder = smp.Unet(
encoder_name=cfg.backbone,
encoder_weights=weight,
classes=cfg.target_size,
activation='identity',
)
self.global_pool = nn.AdaptiveAvgPool2d(1)
def forward(self, image):
output = self.encoder(image)
output = self.global_pool(output)
output = output.view(output.size(0), -1) # Flatten
return output
def build_model(cfg, weight="imagenet"):
print('model_name', cfg.model_name)
print('backbone', cfg.backbone)
model = CustomModel(cfg, weight)
return model
and i try a random tensor :
import torch
import torch.nn.functional as F
input_tensor = torch.randn(1, 3, 256, 256)
weight = "imagenet"
model = build_model(CFG, weight)
output = model(input_tensor)
regression_output = output.squeeze().cpu().detach().numpy()
print(regression_output)
Is it all i should do ?? i mean just set the activation to none (plus avg pool/flatten?) shouldn’t i remove the segmentation head and the decoder part?
I am a bit lost, if someone can just guide me ? It seems logical that i just need the encoder part right?
Have a good day !