Giter Site home page Giter Site logo

wamawama / tnscui2020-seg-rank1st Goto Github PK

View Code? Open in Web Editor NEW
476.0 14.0 77.0 1.51 MB

This is the source code of the 1st place solution for segmentation task in MICCAI 2020 TN-SCUI challenge.

MATLAB 1.80% Python 71.06% Jupyter Notebook 27.14%
tnscui miccai-grand-challenge 1st-place segmentation thyroid-ultrasound-image

tnscui2020-seg-rank1st's Introduction

1st place solution in MICCAI 2020 TN-SCUI challenge

This is the source code of the 1st place solution for segmentation task (with IoU 82.54%) in 2020 TN-SCUI challenge.

[Challenge leaderboard🏆] [中文版readme👁]

Open In Colab Fold1 test results of DDTI dataset in colab

Pipeline of our solution

We use a simple cascaded framework for segmenting nodules, it can be easily extended to other single-target segmentation tasks.

Our pipeline is shown in the figure below. something

Click here to view more details of method

Method

Data preprocessing

Due to different acquisition protocols, some thyroid ultrasound images have irrelevant regions (as shown in the first Figure). First, we remove these regions which may bring redundant features by using a threshold-based approach. Specifically, we perform the operation of averaging along the x and y axes on original images with pixel values from 0 to 255, respectively, after which rows and columns with mean values less than 5 are removed. Then the processed images are resized to 256×256 pixels as the input of the first segmentation network.

Cascaded segmentation framework

We train two networks which share the same encoder-decoder structure with Dice loss function. In practice, we choose DeeplabV3+ with efficientnet-B6 encoder as the first network and the second network. The first segmentation network (at stage Ⅰ of cascade) is trained to provide the rough localization of nodules, and the second segmentation network (at stage Ⅱ of cascade) is trained for fine segmentation based on the rough localization.Our preliminary experiments show that the provided context information in first network may do not play a significant auxiliary role for refinement of the second network. Therefore, we only train the second network using images within region of interest (ROI) obtained from ground truth (GT). (The input data is the only difference in the process of training the two networks.) something When training the second network, we expand the nodule ROI obtained from GT, then the image in the expanded ROI is cropped out and resized to 512×512 pixels for feeding the second network. We observe that, in most cases, the large nodule generally has a clear boundary, and the gray value of small nodule is quite different from that of surrounding normal thyroid tissue (as shown in the above figure). Therefore, background information (the tissue around the nodule) is significant for segmenting small nodules. As shown in Figure below, in the preprocessed image with the size of 256×256 pixels, the minimum external square of the nodule ROI is obtained first, and then the external expansion m is set to 20 if the edge length n of the square is greater than 80, otherwise the m is set to 30. something

Data augmentation and test time augmentation

In both two task, following methods are performed in data augmentation: 1) horizontal flipping, 2) vertical flipping, 3) random cropping, 4) random affine transformation, 5) random scaling, 6) random translation, 7) random rotation, and 8) random shearing transformation. In addition, one of the following methods was randomly selected for additional augmentation: 1) sharpening, 2) local distortion, 3) adjustment of contrast, 4) blurring (Gaussian, mean, median), 5) addition of Gaussian noise, and 6) erasing.

Test time augmentation (TTA) generally improves the generalization ability of the segmentation model. In our framework, the TTA includes vertical flipping, horizontal flipping, and rotation of 180 degrees for the segmentation task.

Cross validation with a size and category balance strategy

5-fold cross validation is used to evaluate the performance of our proposed method. In our opinion, it is necessary to keep the size and category distribution of nodules similar in the training and validation sets. In practice, the size of a nodule is the number of pixels of the nodule after unifying preprocessed image to 256×256 pixels. We stratified the size into three grades: 1) less than 1722 pixels, 2) less than 5666 pixels and greater than 1722 pixels, and 3) greater than 5666 pixels. These two thresholds, 1722 pixels and 5666 pixels, were close to the tertiles, and the size stratification was statistically significantly associated with the benign and malignant categories by the chisquare test (p<0.01). We divided images in each size grade group into 5 folds and combined different grades of single fold into new single fold. This strategy ensured that final 5 folds had similar size and category distributions.

In summary, what we do in our solution are:

  • preprocessing to remove irrelevant regions
  • using a cascaded framework
  • 5-fold cross-validation (CV) strategy with a balanced nodule size and category distribution
  • using test time augmentation (TTA)
  • model ensembling: since we trained two networks separately in 5-fold CV , we combined any one first network and one second network as a pair, and finally we got 25 pairs (or inference results). We use step4_Merge.py to merge 25 inference results into a final ensemble result by pixel-wised voting

Segmentation results on 2020 TN-SCUI training dataset and DDTI dataset

We test our method on 2020 TN-SCUI training dataset(with 3644 images or nodules, malignant 2003 : benign 1641). The segmentation results of 5-fold CV based on "DeeplabV3+ with efficientnet-B6 encoder" are as following:

fold Stage Ⅰ TTA at stage Ⅰ Stage Ⅱ TTA at stage Ⅱ DsC IoU (%)
1 0.8699 79.00
1 0.8775 80.01
1 0.8814 80.75
1 0.8841 81.05
1 0.8840 81.16
1 0.8864 81.44
2 0.8900 81.99
3 0.8827 81.07
4 0.8803 80.56
5 0.8917 82.07
Click here to view complete TNSCUI segmentation results
fold Stage Ⅰ TTA at stage Ⅰ Stage Ⅱ TTA at stage Ⅱ DsC IoU (%)
1 0.8699 79.00
1 0.8775 80.01
1 0.8814 80.75
1 0.8841 81.05
1 0.8840 81.16
1 0.8864 81.44
2 0.8780 80.16
2 0.8825 80.80
2 0.8872 81.52
2 0.8873 81.56
2 0.8894 81.91
2 0.8900 81.99
3 0.8612 78.22
3 0.8744 79.77
3 0.8710 79.59
3 0.8808 80.66
3 0.8753 80.30
3 0.8827 81.07
4 0.8664 78.53
4 0.8742 79.44
4 0.8742 79.80
4 0.8777 80.12
4 0.8771 80.27
4 0.8803 80.56
5 0.8820 80.44
5 0.8874 81.22
5 0.8869 81.38
5 0.8871 81.37
5 0.8913 82.05
5 0.8917 82.07

We also test our method on another open access thyroid nodule ultrasound image dataset (DDTI public database [https://doi.org/10.1117/12.2073532], with 637 images or nodules after our preprocessing and data cleaning). The segmentation results of 5-fold CV based on "DeeplabV3+ with efficientnet-B6 encoder" are as following:

fold Stage Ⅰ TTA at stage Ⅰ Stage Ⅱ TTA at stage Ⅱ DsC IoU (%)
1 0.8391 74.80
1 0.8435 75.49
1 0.8380 74.79
1 0.8406 75.16
1 0.8440 75.77
1 0.8469 76.17
2 0.8392 74.57
3 0.8756 79.61
4 0.8131 72.48
5 0.8576 77.74
Click here to view complete DDTI segmentation results
fold Stage Ⅰ TTA at stage Ⅰ Stage Ⅱ TTA at stage Ⅱ DsC IoU (%)
1 0.8391 74.80
1 0.8435 75.49
1 0.8380 74.79
1 0.8406 75.16
1 0.8440 75.77
1 0.8469 76.17
2 0.8242 72.23
2 0.8295 72.99
2 0.8373 74.30
2 0.8373 74.33
2 0.8373 74.71
2 0.8373 74.57
3 0.8588 77.15
3 0.8672 78.26
3 0.8663 78.42
3 0.8717 78.95
3 0.8712 79.16
3 0.8756 79.61
4 0.8081 71.27
4 0.8110 72.05
4 0.8037 70.85
4 0.8004 70.79
4 0.8151 72.35
4 0.8131 72.48
5 0.8445 75.45
5 0.8523 76.47
5 0.8495 76.53
5 0.8528 77.06
5 0.8535 77.19
5 0.8576 77.74

Reproducing the experiment results

You can follow the step-by-step tutorial below, or just download the pretrained weights and run test_fold1.py to reproduce our results. (note that we only provide the weights of 1st fold in 5-fold CV).

  • The pretrained weights (DeeplabV3+ with efficientnet-B6 encoder) at stage Ⅰ and Ⅱ trained on TN-SCUI and DDTI dataset of fold1 are available at [GoogleDrive] [BaiduWP, password:qxds]
  • The predicted segmentation masks of TN-SCUI final testing dataset (final submission with IoU 82.45%) are available at [GoogleDrive] [BaiduWP, password:qxds]
  • We have processed the DDTI dataset into the format of 2020 TN-SCUI dataset,you can download it from [GoogleDrive] [BaiduWP, password:qxds]

Open In Colab Fold1 test results of DDTI dataset in colab

Statement

We consulted the official organizer of 2020 TN-SCUI via email, and the official reply is that using of external dataset is not allowed in the 2020 TN-SCUI challenge, and participants are not allowed to provide the challenge data anywhere. Therefore, we hereby declare that we did not use any external datasets (such as the DDTI dataset) in the competition, and will not provide TNSCUI data anywhere. The DDTI dataset processed by us is only used as demo data for this code, so that everyone can run the entire scripts with a ready-made data.

How to run this code on the TN-SCUI dataset or your own custom dataset?

This code can be easily performed on single-target segmentation tasks. Here, we split the whole process into 5 steps so that you can easily replicate our results or perform the whole pipeline on your private custom dataset.

You should prepare your data in the format of 2020 TN-SCUI dataset, this is very simple, you only need to prepare:

  • two folders store PNG format images and masks respectively. Note that the file names (ID) of the images and masks should be integers and correspond to each other
  • a csv file that stores the image names (ID) and category. If there is only a segmentation task without a classification task, you can just falsify the category. For example, half of the data randomly is positive , and the other half is negative

Since the sponsor of TNSCUI challenge does not allow the dissemination of the 2020 TN-SCUI dataset, we give another thyroid ultrasound dataset demo for your reference. The demo dataset was derived from the DDTI open access dataset, and we have processed the dataset into the format of 2020 TN-SCUI dataset,you can download it from [GoogleDrive] [BaiduWP, password:qxds].

Step0 preparation of environment

We have tested our code in following environment:

For installing segmentation_models_pytorch (smp), there are two commands:

pip install segmentation-models-pytorch

Use the above command, you can install the released version that can run with torch <= 1.1.0, but without some decoders such as deeplabV3, deeplabV3+ and PAN.

pip install git+https://github.com/qubvel/segmentation_models.pytorch

Use the above command, you will install the latest version which includes decoders such as deeplabV3, deeplabV3+ and PAN, but requiring torch >= 1.2.0.

We modified the original code of smp, to make it can be run with torch <= 1.1.0, and also have the latest version of the smp library encoder such as deeplabV3, deeplabV3+ and PAN. The modified smp is in the filefolder segmentation_models_pytorch_4TorchLessThan120, here are two ways to use it:

  1. install smp with pip install segmentation-models-pytorch firstly, then just copy the segmentation_models_pytorch_4TorchLessThan120 into your project folder to use it
  2. copy the segmentation_models_pytorch_4TorchLessThan120 into your project folder, then install these libs: torchvision>=0.3.0, pretrainedmodels==0.7.4, efficientnet-pytorch>=0.5.1

Step1 preprocessing

👀This step is optional, if you donot wanna preprocess image, just prepare your data as the demo format and skip to the Step2"training and validatation".

In step1, you should run the script step1_preprocessing.m in MATLAB to perform the preprocessing. For both TN-SCUI and DDTI dataset, there are some irrelevant regions to be removed. Because we used a cross-validation with a nodule size and category balance strategy, we should get the size of nodules for cross-validation.

After the code runs, you will get two folders and a csv file:

  • the two filefolders are named stage1 and stage2, the data in folder stage1 is used to train the first network, which contains the preprocessed image with no irrelevant regions; and stage2 is used to train the second network, which contains the image in the expanded ROI
  • the csv file named train.csv with below dataformat, the size of a nodule is the number of pixels of the nodule after unifying preprocessed image to 256×256 pixels
id cate size
001.PNG 0 2882
002.PNG 1 3277
003.PNG 1 3222
004.PNG 1 256

The example of preprocessed DDTI dataset was given here [GoogleDrive] [BaiduWP, password:qxds]

Step2 training and validatation

For training phase:

In step2, you should run the script step2_TrainAndValidate.py to train the first or second network in the cascaded framework (you need to train the two networks separately), that is, the training process (such as hyperparameters) is the same for both first and second network except for the different training datasets used. With the csv file train.csv, you can directly perform K-fold cross validation (default is 5-fold), and the script uses a fixed random seed to ensure that the K-fold cv of each experiment is repeatable (please note that the same random seed may cause different K-fold under different versions of scikit-learn).

For example, you can train the first fold of the first network in two ways:

  1. modify (set) following parameters in the script step2TrainAndValidate.py and run the script.
""" just set your param as the default value """
# hyperparameters
parser.add_argument('--image_size', type=int, default=256)  # recommended: 256 for 1st(stageⅠ) network, 512 for 2nd(stage Ⅱ) network👍
parser.add_argument('--batch_size', type=int, default=3)
parser.add_argument('--batch_size_test', type=int, default=30)
# custom parameters
parser.add_argument('--Task_name', type=str, default='dpv3plus_stage1_', help='DIR name,Task name')
parser.add_argument('--csv_file', type=str, default='./DDTI/2_preprocessed_data/train.csv')
parser.add_argument('--filepath_img', type=str, default='./DDTI/2_preprocessed_data/stage1/p_image')
parser.add_argument('--filepath_mask', type=str, default='./DDTI/2_preprocessed_data/stage1/p_mask')
parser.add_argument('--fold_K', type=int, default=5, help='number of cross-validation folds')
parser.add_argument('--fold_idx', type=int, default=1)
  1. use the following command at the terminal to transmit parameters and run the script.
python step2_TrainAndValidate.py \
--batch_size=3 \
--Task_name='dpv3plus_stage1_'\
--csv_file='./DDTI/2_preprocessed_data/train.csv' \
--filepath_img='./DDTI/2_preprocessed_data/stage1/p_image' \
--filepath_mask='./DDTI/2_preprocessed_data/stage1/p_mask' \
--fold_idx=1

Something else in training process:

  • when the GPU is geforce 1080ti, the training batchsize can be set as 10 for first network and 3 for second network, and testing batchsize can be set as 30 for both network
  • the weights with the highest IoU on the validation set will be saved
  • by specifying the parameter fold_idx from 1 to K and running repeatedly, you can complete the training of all K folds. The results will be saved in the result folder under the project. You can view the training log in real time through tensorboardX
  • for training the second network, you only need to change the path of the training data (filepath_img and filepath_mask) and Task_name
  • we do not validation set during training, actually only use the training set and the test set, and copy the test set to the validation set. If you need to use a validation set, you can specify the parameter validate_flag as True in the script step2TrainAndValidate.py
  • if you do not want to perform cross-validation, or have already prepared a train and validate and test set, just modify the code in the funtion main() with following code:
train_list = get_filelist_frompath(train_img_folder,'PNG') 
train_list_GT = [train_mask_folder+sep+i.split(sep)[-1] for i in train_list]
test_list = get_filelist_frompath(test_img_folder,'PNG') 
test_list_GT = [test_mask_folder+sep+i.split(sep)[-1] for i in test_list]

For validation and testing phase

In fact, there is no need to re-run the script, because the test has been performed during the training process, and the detailed information of the result is recorded in the record.xlsx or record.txt. But you can also confirm the final training effect by running the script step2TrainAndValidate.py after the training by setting the parameter mode as test.

It should be noted that the dataset validated in the training phase is preprocessed. Therefore, if you want to perform test based on the original unprocessed images, please refer to step3.

Step3 testing (or inference or predicting)

In step3, you should run the script step3_TestOrInference.py to perform inference based on the original unprocessed image. By using the script step3_TestOrInference.py, you can:

  • perform test of cross-validation (based on the original unprocessed images)
  • inference on new data

Here are some parameters should be noticed (Especially c1_size and c2_size):

fold_flag = False # False for inference on new data, and True for cross-validation
mask_path = None  # None for inference on new data
save_path = None  # If you don't want to save the inference result, set it to None
c1_size = 256  # The input image size for training the first network ❗
c1_tta = False # Whether to use TTA for the first network
orimg=False    # False for no preprocessing to remove irrelevant areas
use_c2_flag = False # Whether to use the second network
c2_size = 512 # The input image size for training the second network ❗
c2_tta = False # Whether to use TTA for the second network

When you get multiple results after inference, you can use the script step4_Merge.py to integrate all the results. We use a pixel-wised voting method, and recommend voting on odd numbers of results to avoid fluctuations in making decision.

Acknowledgement

  • Thanks to the organizers of the 2020 TN-SCUI challenge
  • Thanks to the open access DDTI dataset for providing ultrasound data and annotation of thyroid nodules
  • Thanks to qubvel, the author of smg and ttach, all network and TTA used in this code come from his implement

tnscui2020-seg-rank1st's People

Contributors

bonny-zyy avatar lovelyyutian avatar wamawama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tnscui2020-seg-rank1st's Issues

你好,我在自己数据集使用你的方案,级联两个网络后IoU比只用第一个网络还低了?

您好,感谢你分享的优秀方案。我在自己数据集上复现时遇到一些问题,想跟您交流下:
数据集:
我使用TNSCUI公开的训练集重新按照8:2划分为训练集(2915)和测试集(729),然后按照你的预处理方法进行处理生成stage1和stage2的数据。
问题:
按照你描述的步骤,采用5折交叉验证,训练完fold_1 后发现stage1网络在验证集上的IoU(0.804),stage2网络单独在验证集上测试I oU(0.85)。级联两个网络一起测试的IoU只有0.776。
我不知道哪里出了问题,按理说级联两个网络结果至少不会比第一个网络差吧?
另外,训练第二个网络时,除了改image和mask路径外,image_size是否也要改成512?

About the Reproducing the experiment results in colab

I test the script test_fold1.py with DDTI dataset and corresponding weights, and the results of the first fold are correct when running script in my local environment (e.g., IoU is 76.17% with both first and second networks). But when I test the script in colab, the results are wrong (with IoU of 74.58%).
I have tried to adjust the colab environment, but still cannot reproduce the results 😵.

  • Fold1 results of DDTI dataset in my local environment, [link]
IOU_final 0.7617019912949896
DSC_final 0.8468769601199299
  • Fold1 results of DDTI dataset in colab Open In Colab
IOU_final 0.7458269486726278
DSC_final 0.8384947545187682

ask help

I would like to ask the author, when running step2to4_train_validate.py, the train [Validation] Acc: 0.9534, SE: 0.0000, SP: 0.0000, PC: 0.0000, Dice: 0.0000, IOU: 0.0000 Why do I get these results is 0?

请问如何解决决这一AssertionError

File "/content/drive/Shareddrives/[email protected]/TNSCUI2020-Seg-Rank1st/step2to4_train_validate_inference/loader/data_loader.py", line 281, in getitem
[image, GT] = data_aug(image, GT)
File "/content/drive/Shareddrives/[email protected]/TNSCUI2020-Seg-Rank1st/step2to4_train_validate_inference/loader/img_mask_aug.py", line 117, in data_aug
images_aug = seq_det.augment_images(imgs) # 进行增强
File "/usr/local/lib/python3.7/dist-packages/imgaug/augmenters/meta.py", line 542, in augment_images
"got shape %s." % (images.shape,))
File "/usr/local/lib/python3.7/dist-packages/imgaug/imgaug.py", line 1869, in do_assert
raise AssertionError(str(message))
AssertionError: Expected 3d/4d array of form (N, height, width) or (N, height, width, channels), got shape (256, 256).

作者您好,我在复现项目的时候,运行到step2的时候就遇到很多问题,想请您解答下!

Traceback (most recent call last):
File "/mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 189, in
main(config)
File "/mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 116, in main
solver.train()
File "/mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/tnscui_utils/solver.py", line 245, in train
for i, sample in enumerate(self.train_loader):
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 630, in next
data = self._next_data()
^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 1345, in _next_data
return self._process_data(data)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 1371, in _process_data
data.reraise()
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/_utils.py", line 694, in reraise
raise exception
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/utils/worker.py", line 308, in worker_loop
data = fetcher.fetch(index)
^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/utils/fetch.py", line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/torch/utils/data/utils/fetch.py", line 51, in
data = [self.dataset[idx] for idx in possibly_batched_index]
~~~~~~~~~~~~^^^^^
File "/mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/loader/data_loader.py", line 281, in getitem
[image, GT] = data_aug(image, GT)
^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/loader/img_mask_aug.py", line 117, in data_aug
images_aug = seq_det.augment_images(imgs) # 进行增强
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 822, in augment_images
return self.augment_batch
(
^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 641, in augment_batch

batch_inaug = self.augment_batch(
^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3124, in augment_batch
batch = self[index].augment_batch
(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 641, in augment_batch

batch_inaug = self.augment_batch(
^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3395, in augment_batch
augmenter_active = self._get_augmenter_active(batch.nb_rows,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/imgaug/augmenters/meta.py", line 3368, in _get_augmenter_active
augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool)
^^^^^^^
File "/home/alan/miniforge3/envs/torch/lib/python3.11/site-packages/numpy/init.py", line 324, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
np.bool was a deprecated alias for the builtin bool. To avoid this error in existing code, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_ here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

ERROR conda.cli.main_run:execute(47): conda run python /mnt/c/Users/Alan/Desktop/TNSCUI2020-Seg-Rank1st-master/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py failed. (See above for error)

进程已结束,退出代码为 1

关于step3执行过程中的问题

你好,我翻看之前您回答的问题已经解决了指标显示异常的问题,但是在执行step3进行预测的时候出现了错误,一直没有解决,由于是新手,希望您有时间能帮忙看一下我这个应该是哪里出了问题,谢谢。
屏幕截图 2021-05-13 153633

关于图片裁剪

感谢作者开源代码,在复现的时候发现了个问题:对于图片裁剪,matlab和python裁剪结果不一致,matlab裁剪貌似对于多个目标更好,python代码对多个目标只会选取一个来裁剪。这种有什么好的解决方法吗?

关于数据预处理

使用基于阈值的数据预处理删除TNSCUI的冗余信息部分的时候发现对于大多数图片无效。这是因为阈值的原因吧,就是TNSCUI数据集不是大部分是已经删除了冗余信息,还有少部分含有冗余信息,再使用您的代码好像这些部分含有冗余信息的图片还是没有删除冗余信息啊。期待您的回复!

推理过程中,flod_flag设为False时预测结果为0。

作者,你好!我在运行推理函数step3_TestOrInference.py时,将fold_flag设为False后模型预测结果直接输出为0。但是当我将flod_flag设为True时,模型可以输出结果。会有预测结果图像生成。
image

下面是我更改的代码部分:
img_path = r'tn3k_dian2\tn3k_point\test-image'
mask_path = r'tn3k_dian2\tn3k_point\test-mask'
csv_file = r'tn3k_dian2\output.csv'
save_path = r'inference'

# 是否使用设定好的分折信息
fold_flag =False  # 预测测试集则设置为False直接读取img_path中PNG文件进行测试,True则使用分折信息

使用的模型权重文件也存在:
weight_c1=r'result\TNSCUI\dpv3plus_stage1_5_1\models\epoch400_Testdice0.0000.pkl'
weight_c2=r'result\TNSCUI\dpv3plus_stage2_5_1\models\epoch400_Testdice0.0000.pkl'

请问问题出在哪里?

a question about classification

你好,想问一下,通过你这个网络进行instance segmentation 从而进行分类,和对甲状腺结节处进行crop,然后再送入到一个分类网络,哪个分类的效果好些?

数据处理问题

您好,您提到“在预处理后大小为256x256像素的图像中,首先得到结节感兴趣区域的最小外平方,然后若正方形边长n大于80,则外扩m为20,否则m为30。”,请问这里的80、20、30这三个数据是否有理论依据呢?还是您这边通过实验得到的经验值呢?

关于DDTI数据的问题

您好,想请问一下:您所列出的DDTI结果也是基于该数据集进行独立五折交叉验证的训练测试流程得到的吗?训练过程中有没有用到挑战赛的数据呢?

请问图片预处理时x_hold_range计算中的数值是怎么得到的?

x_hold_range = list((len(value_x) * np.array([0.24 / 3, 2.2 / 3])).astype(np.int))
y_hold_range = list((len(value_y) * np.array([0.8 / 3, 1.8 / 3])).astype(np.int))

你好,关于上面代码中的0.24 / 3, 2.2 / 3,0.8 / 3, 1.8 / 3这几个数值,我理解的是这四个值表示行方向和列方向中不能被裁切的范围,但是不太明白为什么要设定这个范围,以及这个范围是怎么计算得到的。如果我要用其他的数据集,要修改这些值吗?

ask heip

Hello,i have some of the code is not clear .

In slover.py
self.unet = smp.DeepLabV3Plus(encoder_name="efficientnet-b6",
encoder_weights='imagenet',
in_channels=self.img_ch, classes=1)
therein encoder_name="efficientnet-b6" refers to the name of the second stage enconder

使用自己数据集时报错

RuntimeError: Given groups=1, weight of size [56, 1, 3, 3], expected input[16, 3, 257, 257] to have 1 channels, but got 3 channels instead

如何安装torch==1.1.0 torchvision==0.4.0

您好,我在pytorch官网查找1.1.0版本的torch,发现1.1.0版本对应的torchvision版本为0.3.0
pip install torch==1.1.0 torchvision==0.3.0
但您要求torchvision==0.4.0
在我通过pip install torch==1.1.0安装完torch后,执行pip install torchvision==0.3.0 提示找不到该版本的torchvision

ValueError: invalid literal for int() with base 10: 'D:\\TNSCUI2020-Seg-Rank1st-master\\DDTI\\1_or_data\\image\\20155'

大神您好,
当我在跑step2时出现了这样的报错“ValueError: invalid literal for int() with base 10: 'D:\TNSCUI2020-Seg-Rank1st-master\DDTI\1_or_data\image\20155'”

train bs size torch.Size([10, 1, 256, 256])
|█████████████████████████████████████████████████-| 98.0% batch_total_loss:0.8571638 lovz_loss:1.3810241 bi_BCE_loss:0.62739336 dice_loss:0.8571638 1e-12
train bs size torch.Size([10, 1, 256, 256])
|██████████████████████████████████████████████████| 100.0% batch_total_loss:0.83332884 lovz_loss:1.3876538 bi_BCE_loss:0.6468584 dice_loss:0.83332884
per epoch training cost Time 00 h:13 m:55 s
Epoch [1/40], Loss: 0.8418
1e-12
@,,@ testing with TTA
Traceback (most recent call last):
File "D:/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 188, in
main(config)
File "D:/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 114, in main
solver.train()
File "D:\TNSCUI2020-Seg-Rank1st-master\step2to4_train_validate_inference\tnscui_utils\solver.py", line 355, in train
acc, SE, SP, PC, DC, IOU= self.test_tta(mode='valid')
File "D:\TNSCUI2020-Seg-Rank1st-master\step2to4_train_validate_inference\tnscui_utils\solver.py", line 565, in test_tta
tmp_index = int(tmp_index.split('.')[0][:])
ValueError: invalid literal for int() with base 10: 'D:\TNSCUI2020-Seg-Rank1st-master\DDTI\1_or_data\image\20155'

请问这个问题该怎么解决呢?

请问级联网络是怎么定义的

大佬你好,感谢你的分享,写的很详细!
关于网络我有点疑惑,stage1和stage2使用的网络都是相同的deeplabv3+efficient吗?是使用同一个网络训练两次最后再将结果做集成吗?
期待您的回复,谢谢。

关于step1中使用自己数据集的问题

csv中数据如下:
截图_20215302105359
当我运行step1_preprocessing.m文件报错:
截图_20215502105521
运行到第二条数据没有gt框的数据报错,第一条有mask是正常的
请问使用自定义数据集有什么注意的吗?

关于实验可重复性的提问

您好,在您的项目中应该没有考虑实验可重复性的问题吧,就是即使是相同的代码和数据集,每次重新运行,最后结果都会稍有不同吧。我尝试使实验可重复,因为想公平比较模型的性能,如果本身就有随机性的话,就无法确定是代码本身随机性导致最后结果不同,还是模型的改进了。我在step2_TrainAndValidate.py(主要训练模型的那个文件中)开头添加了如下代码:
image
但是发现训练过程中,每一个epoch指标还是不一样,请问您有什么关于保证实验可重复性的经验吗,想请教,多谢

关于使用step3_TestOrInference.py函数对未处理图像进行预测时,无法找到预测图像

你好,作者!我今天使用step3_TestOrInference.py函数进行预测时,Image.open(mask_file)函数出错。报错内容如下:
File "f:/liuxiao/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step3_TestOrInference.py", line 202, in
GT = Image.open(mask_file)
File "F:\miniconda\envs\TNSCUI_Rank1\lib\site-packages\PIL\Image.py", line 3218, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'tn3k_dian2\tn3k_point\test-mask\0050'
预测数据集我放在在项目运行主目录下,应该不是由于没有使用绝对路径问题。我在训练模型时,读取图像的路径也使用的是相对路径。我猜想是不是由于Iamge.open函数的问题?

DDTI数据集的处理

你好,请问关于将DDTI数据集中根据xml中的坐标画出结节mask那个黑白图的代码,您有吗,想请教一下,不胜感激。

About IOU

Hi,
Thanks for sharing code!W
我想用已有的model作为预训练的模型,然后继续用自己的数据训练,但为了先验证模型的正确性,我在DDTI先做了fine-tune, 可IOU, SE, SP等指标都为0 , 理论上不fine-tine, 这几个值都不应该为0的, 我使用的是step2的脚本,我发现网络train出来的结果非常小,达不到0.5的阈值,想问下是什么原因呢?谢谢

image

Question about DDTI dataset

Hi, I downloaded the original DDTI dataset, which only contains 480 images, but the dataset you processed contains 637 images. I was confused where did you get extra images? I am looking forward to your reply, thanks. @WAMAWAMA

augmentation_prob

is you set augmentation_prob=1,this mean every train sample all do data augument? 请问对所有的训练数据都做了增强,这样不就丢失了原始训练数据吗?

ValueError: invalid literal for int() with base 10: '3jbOZBlx'

大佬,还请教个问题,当我用自己的数据集跑的时候,报错如下所示,我发现您的数据文件都是用整数命名的,而我的都是字母,假如文件名不使用数字而是字母的话需要在哪里更改代码呢?
per epoch training cost Time 00 h:26 m:09 s
Epoch [1/40], Loss: 0.5587
1e-12
@,,@ testing with TTA
Traceback (most recent call last):
File "D:/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 188, in
main(config)
File "D:/TNSCUI2020-Seg-Rank1st-master/step2to4_train_validate_inference/step2_TrainAndValidate.py", line 114, in main
solver.train()
File "D:\TNSCUI2020-Seg-Rank1st-master\step2to4_train_validate_inference\tnscui_utils\solver.py", line 352, in train
acc, SE, SP, PC, DC, IOU= self.test_tta(mode='valid')
File "D:\TNSCUI2020-Seg-Rank1st-master\step2to4_train_validate_inference\tnscui_utils\solver.py", line 564, in test_tta
tmp_index = int(tmp_str_.split('\')[-1]) #tmp_index = int(tmp_str_.split('\')[-1])
ValueError: invalid literal for int() with base 10: '3jbOZBlx'

有关DDTI数据集的分类问题

您好,请问有没有DDTI数据集的类别标签,category.csv这个文件中提示类别信息是伪造的,不可以用作分类任务

第一阶段训练时候的问题

大神您好,我有些疑问,麻烦您回答下,

第一个问题,readme中,脚本中设置参数:
parser.add_argument('--filepath_img', type=str, default='./DDTI/2_preprocessed_data/stage1/p_image')
parser.add_argument('--filepath_mask', type=str, default='./DDTI/2_preprocessed_data/stage1/p_image')
请问下,第二个参数:--filepath_mask,对应的路径不应该是p_mask文件吗?

第二个问题,为什么我在训练第一阶段时,验证集的指标除了ACC都是0呢(每一个epoch都是)?IOU也是0
Epoch [23/405], Loss: 0.2362
9.948524919112924e-05
@,,@ testing with TTA
[Validation] Acc: 0.9521, SE: 0.0000, SP: 0.0000, PC: 0.0000, Dice: 0.0000, IOU: 0.0000
per epoch testing&vlidation cost Time 00 h:00 m:07 s

第三个问题,第二阶段的所需要的数据集,是怎么获得的,依靠的哪句代码?
torchvision.utils.save_image(images_all.data.cpu(), os.path.join(self.result_path, 'images', '%s_%d_image.png' (mode, i)), nrow=self.batch_size)
是这句吗?并没有发现保存mask到stage2文件夹目录下

打扰了,十分感谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.