askerlee / segtran

Medical Image Segmentation using Squeeze-and-Expansion Transformers
216 stars 49 forks source link

train #32

Open StevenJ308 opened 2 years ago

StevenJ308 commented 2 years ago

Thanks for your great project! Sir,I want to train new 2D data with pretrained model,how could I do that?

askerlee commented 2 years ago

Well you need to edit the big dictionary default_settings and add the dataset. You can refer to 'fundus' or 'polyp' in the dictionary. I know it's ad-hoc. But currently I don't have a big chunk of time to make the code more elegant.

StevenJ308 commented 2 years ago

Thank you so much for your kind.Sir,I am a little puzzeld.I don't know where the 'big dictionary default_settings' is.I have downloaded the REFUGE dataset and your checkpoint.It works well in REFUGE dataset.But when I use the images pictured by my phone.It doesn't work well.So I want to train some images with noise and some pictured by phone on the foundation of your checkpoint.However,I don't know how to set it. Is it true to change the checkpoint_path so that I can train on the foundation of your work?
image

askerlee commented 2 years ago

Are the photos you take also fundus images? and you want to mix them with the REFUGE data? If so, there are a few steps to take. 1. Preprocess the images by cropping them using MNet_DeepCDR, and keeping the optic cup/disc areas. 2. You create a folder under data/fundus, say "cam", and two subfolders under "cam": "images" and "masks". Put cropped images under "images". Annotate the images by opthalmologists, and put the masks under "masks". 3. Add "cam" into the "fundus" sub-dictionary in train2d.py, including "ds_names", "uncropped_size", "has_mask" and "weight". If the image size is not fixed, then you need also specify "orig_dir" and "orig_ext", which is used by the algorithm to find the original image size and generate a segmentation map that's of the same size.

StevenJ308 commented 2 years ago

Yes,sir.I have already preprocessed the images.I want to do 'Incremental Learning',but I do not confirm how to train the new fundus image with pretrained weights which you offered.Is it true to change the 'checkpoint_path' to use the pretrained weights? Or there maybe some other settintgs need to change?

askerlee commented 2 years ago

To load the pretrained weight, you just add "--cp path_to_pretrained_weight" to the training command line. But in the screenshot above, it looks like the error is in the dataloader.

StevenJ308 commented 2 years ago

OK,I will try it.Thanks again for your patient and kind.Have a nice day.

StevenJ308 commented 2 years ago

Sir.sorry,but I have another question.When I train a new fundus dataset,I found there is a file called fundus-cropped-gray0.5-stats.json,I showed it in the picture below,how could I set the number list of mean/std for my dataset? B~0T ~QJXOE9%X _~KMR23S

askerlee commented 2 years ago

You can run "calcstat.py" to generate the mean and std of a particular folder of images. Sorry I didn't explain it in the documentation. Will add a description once I got some time.

StevenJ308 commented 2 years ago

Thanks,sir.A great project,it's my carelessness.When I run the train.py with trainning command line,It exits a error.When I debug it,it shows 'ds_name':[train,valid,drishiti,test,rim] without 'cam'.However,I have added it into 'fundus' sub-dictionary including "ds_names", "uncropped_size", "has_mask" and "weight". }B_P 3EX{VB~@% FA) {6M

askerlee commented 2 years ago

Oh I realized you don't have to put "cam" into "ds_names". It's the default list of training datasets to load. You can also specify whatever list of training datasets in the commandline, like python3 train2d.py --ds "dataset_a,dataset_b" ...

I guess the error was caused in other places.

StevenJ308 commented 2 years ago

Sir,I have used the trainning command line.There was a error called 'args[sample_num]=[-1] checkpoint args[sample_num]=[-1,-1,-1,-1,-1] inconsistent'.But I set the sample_num = None,and there is just a ds_name called 'cam',I do not know why the list has five numbers.

askerlee commented 2 years ago

This is a tiny bug that I just patched. Could you please pull the latest code and try again? If you've modified the code, please manually add "sample_num" in the list ignored_keys.

StevenJ308 commented 2 years ago

Yes,I have done it.But it shows "KeyError:'perturb_pew_range'"

StevenJ308 commented 2 years ago

{)WHBREHC{L~4`Z1G6)FR$E

askerlee commented 2 years ago

'perturb_pew_range' should also be added to ignored_keys. As I change the code from time to time, there could be multiple such errors. Could you keep adding error keys and then tell me what's missing? Thanks.

StevenJ308 commented 2 years ago

Of course,Sir.With pleasure

StevenJ308 commented 2 years ago

Sir,I have added a few keys including 'pos_embed_every_layer','pos_in_attn_only','attention_mode_dim','ablate_pos_embed_type',then it shows RuntimeError: Error(s) in loading state_dict for Segtran2d: Unexpected key(s) in state_dict: "voxel_fusion.pos_embed_layer.pos_embedder.pos_fc.weight", "voxel_fusion.pos_embed_layer.pos_embedder.pos_fc.bias"

askerlee commented 2 years ago

Sorry this error is because I renamed a few variables. Now I've fixed the bug, meanwhile I also updated the checkpoint. You can download the new checkpoint on baidu netdisk or from the dropbox link: https://www.dropbox.com/s/rmonw2giyymu918/refuge2-09041428-5000.pth.zip?dl=0

After updating to the newest code, you should be able to load the new checkpoint smoothly.

StevenJ308 commented 2 years ago

Thanks a lot.I have renamed the state_dict's key name to match the params,WD$XN4L~WJZC)IAL {`V5VN.I will try the new checkpoint,thanks again.