Mismatched Dimensions of input and output (couldn't visualize the result)
ytliang97 opened this issue · 3 comments
Hi, thank you for sharing.
I follow your tutorial to train a model with two .nii samples.
It trained success and could be tested, but I noticed one thing that the shape of the model output didn't match with the input's whether I use raw data or fixed data as input data.
I use LiTS dataset number 28 data for testing.
Here is the code:
checkDimension.py
import SimpleITK as sitk
from scipy import ndimage
def sitk_read_raw(img_path, resize_scale=1): # 读取3D图像并resale(因为一般医学图像并不是标准的[1,1,1]scale)
nda = sitk.ReadImage(img_path)
if nda is None:
raise TypeError("input img is None!!!")
nda = sitk.GetArrayFromImage(nda) # channel first
nda=ndimage.zoom(nda,[resize_scale,resize_scale,resize_scale],order=0) #rescale
return nda
if __name__ == '__main__':
input_name = './fixed_data/data/volume-28.nii'
data_np = sitk_read_raw(input_name)
print('model input shape: {:}'.format(data_np.shape))
output_name = './output/model2/result/result-28.nii'
data_np = sitk_read_raw(output_name)
print('model output shape: {:}'.format(data_np.shape))
raw_data = './raw_dataset/LiTS_batch2/data/volume-28.nii'
data_np = sitk_read_raw(raw_data)
print('raw data shape: {:}'.format(data_np.shape))
raw_label = './raw_dataset/LiTS_batch2/label/segmentation-28.nii'
data_np = sitk_read_raw(raw_label)
print('raw data shape: {:}'.format(data_np.shape))
The result is:
model input shape: (122, 512, 512)
model output shape: (64, 256, 256)
raw data shape: (129, 512, 512)
raw label shape: (129, 512, 512)
I want to visualize it with ITK-SNAP.
The original data could be visualized like this:
But currently, the output shape of the model can't be visualized like above:
I still can't find out where the code I should edit to meet my needs. Could you give me some advice? Thank you!
- When making inferences, original data should be used instead of fixed_data (please refer to
test.py
). - The shape of the data is inconsistent because the original data was resized (default=0.5) before being input to the network. Therefore, you can set resize_scale to 1 in
config.py
, or use nearest neighbor interpolation to magnify the prediction result twice (recommended, much less calculation).
Thank you for replying, I'll check it.
The problem has been solved. Thank you!