ModelsGenesis icon indicating copy to clipboard operation
ModelsGenesis copied to clipboard

Questions about data pre-processing.

Open Med-Process opened this issue 3 years ago • 1 comments

This is a wonderful work, and there are some questions about data perocessing. Question 1: When preparing our own image data, we always scale the data between -1 and 1. And I see the author process the data into 0 and 1. Is it necessary to scale the input data to 0 and 1?

Question 2: The author provide a UNet3D based model, and the number of the model class is 1. If we want use the author's pretrained model with 4 class (or other class), is it worked by loading the network layer without "module.out_tr.final_conv.weight", and just fine-tune the model? Do we need fixing the model layer and with a two stage training?

Thanks and looking forward your reply!

Med-Process avatar Oct 14 '20 03:10 Med-Process

Hi @Med-Process

Question 1: I recommend scaling the input into [0, 1] because the pre-trained model was trained in such configuration. There are two popular pre-processing strategies: min-max and z-score. The former normalizes the intensity value into [0, 1] and the latter standardizes the value by subtracting mean and dividing standard deviation. I'm not aware of the pre-processing that scales the data to [-1, 1].

Question 2: You can load the entire weights, cut the last layer, and append layers that you need for different numbers of classes. Note that the appended layers are randomly initialized. How exactly to do this, you may want to check the example here: https://github.com/MrGiovanni/ModelsGenesis/tree/master/pytorch#3-fine-tune-models-genesis-on-your-own-target-task

Specifically, this part:

class TargetNet(nn.Module):
    def __init__(self, base_model,n_class=1):
        super(TargetNet, self).__init__()

        self.base_model = base_model
        self.dense_1 = nn.Linear(512, 1024, bias=True)
        self.dense_2 = nn.Linear(1024, n_class, bias=True)

    def forward(self, x):
        self.base_model(x)
        self.base_out = self.base_model.out512
        self.out_glb_avg_pool = F.avg_pool3d(self.base_out, kernel_size=self.base_out.size()[2:]).view(self.base_out.size()[0],-1)
        self.linear_out = self.dense_1(self.out_glb_avg_pool)
        final_out = self.dense_2( F.relu(self.linear_out))
        return final_out

Please let me know if you have further questions.

Best, Zongwei

MrGiovanni avatar Nov 02 '20 22:11 MrGiovanni