airlab-unibas / airlab

Image registration laboratory for 2D and 3D image data
Apache License 2.0
408 stars 92 forks source link

Error with Mutual Information loss. #12

Closed MountainAndMorning closed 4 years ago

MountainAndMorning commented 5 years ago

I change the MSE loss to the MI loss in the affine_registration_3d.py example and get the error below. Any one know how to fix it.

(simpleitk) iridium-MacBook:airlab iridium$ python /Users/iridium/Desktop/airlab-master/examples/affine_registration_3d.py
tensor(-0.5714) tensor(-0.5714)
0 mi: 1.9073486328125e-06 
1 mi: -1.9073486328125e-06 
2 mi: -1.9073486328125e-06 
3 mi: -0.0 
4 mi: 1.9073486328125e-06 
5 mi: -1.9073486328125e-06 
6 mi: -1.9073486328125e-06 
7 mi: -0.0 
8 mi: -9.5367431640625e-07 
9 mi: -0.0 
10 mi: -0.0 
11 mi: -1.9073486328125e-06 
12 mi: -9.5367431640625e-07 
13 mi: -0.0 
14 mi: -0.0 
15 mi: 9.5367431640625e-07 
16 mi: -1.9073486328125e-06 
17 mi: -0.0 
18 mi: -0.0 
19 mi: -1.9073486328125e-06 
20 mi: -9.5367431640625e-07 
21 mi: -9.5367431640625e-07 
22 mi: -1.9073486328125e-06 
23 mi: 9.5367431640625e-07 
24 mi: -9.5367431640625e-07 
25 mi: -9.5367431640625e-07 
26 mi: -9.5367431640625e-07 
27 mi: -9.5367431640625e-07 
28 mi: -9.5367431640625e-07 
29 mi: -9.5367431640625e-07 
30 mi: -9.5367431640625e-07 
31 mi: -0.0 
32 mi: -9.5367431640625e-07 
33 mi: -3.814697265625e-06 
34 mi: -0.0 
35 mi: 9.5367431640625e-07 
36 mi: -0.0 
37 mi: -0.0 
38 mi: -9.5367431640625e-07 
39 mi: -2.86102294921875e-06 
40 mi: 9.5367431640625e-07 
41 mi: -9.5367431640625e-07 
42 mi: -1.9073486328125e-06 
43 mi: -0.0 
44 mi: -1.9073486328125e-06 
45 mi: -0.0 
46 mi: -9.5367431640625e-07 
47 mi: -3.814697265625e-06 
48 mi: -9.5367431640625e-07 
49 mi: -0.0 
50 mi: 9.5367431640625e-07 
51 mi: -9.5367431640625e-07 
52 mi: -9.5367431640625e-07 
53 mi: -0.0 
54 mi: -0.0 
55 mi: -9.5367431640625e-07 
56 mi: -0.0 
57 mi: -9.5367431640625e-07 
58 mi: -0.0 
59 mi: -0.0 
60 mi: -9.5367431640625e-07 
61 mi: -1.9073486328125e-06 
62 mi: -2.86102294921875e-06 
63 mi: -9.5367431640625e-07 
64 mi: -1.9073486328125e-06 
65 mi: -0.0 
66 mi: -0.0 
67 mi: -9.5367431640625e-07 
68 mi: -9.5367431640625e-07 
69 mi: -0.0 
70 mi: -0.0 
71 mi: -1.9073486328125e-06 
72 mi: -9.5367431640625e-07 
73 mi: -9.5367431640625e-07 
74 mi: -0.0 
75 mi: -1.9073486328125e-06 
76 mi: -0.0 
77 mi: -9.5367431640625e-07 
78 mi: -1.9073486328125e-06 
79 mi: -9.5367431640625e-07 
80 mi: -0.0 
81 mi: -9.5367431640625e-07 
82 mi: -0.0 
83 mi: 9.5367431640625e-07 
84 mi: -2.86102294921875e-06 
85 mi: -0.0 
86 mi: -1.9073486328125e-06 
87 mi: -2.86102294921875e-06 
88 mi: -0.0 
89 mi: -1.9073486328125e-06 
90 mi: -1.9073486328125e-06 
91 mi: -1.9073486328125e-06 
92 mi: 9.5367431640625e-07 
93 mi: -2.86102294921875e-06 
94 mi: -1.9073486328125e-06 
95 mi: 9.5367431640625e-07 
96 mi: -1.9073486328125e-06 
97 mi: -0.0 
98 mi: -0.0 
99 mi: -2.86102294921875e-06 
100 mi: -9.5367431640625e-07 
101 mi: -0.0 
102 mi: -0.0 
103 mi: -0.0 
104 mi: -9.5367431640625e-07 
105 mi: 9.5367431640625e-07 
106 mi: 9.5367431640625e-07 
107 mi: -0.0 
108 mi: -0.0 
109 mi: -0.0 
110 mi: -0.0 
111 mi: -0.0 
112 mi: -9.5367431640625e-07 
113 mi: 9.5367431640625e-07 
114 mi: -9.5367431640625e-07 
115 mi: -9.5367431640625e-07 
116 mi: -9.5367431640625e-07 
117 mi: -0.0 
118 mi: -9.5367431640625e-07 
119 mi: 1.9073486328125e-06 
120 mi: -9.5367431640625e-07 
121 mi: 9.5367431640625e-07 
122 mi: 9.5367431640625e-07 
123 mi: 1.9073486328125e-06 
124 mi: -0.0 
125 mi: -0.0 
126 mi: -0.0 
127 mi: -0.0 
128 mi: -0.0 
129 mi: -9.5367431640625e-07 
130 mi: 9.5367431640625e-07 
131 mi: -1.9073486328125e-06 
132 mi: -9.5367431640625e-07 
133 mi: -9.5367431640625e-07 
134 mi: -2.86102294921875e-06 
135 mi: -0.0 
136 mi: 9.5367431640625e-07 
137 mi: -9.5367431640625e-07 
138 mi: -0.0 
139 mi: -9.5367431640625e-07 
140 mi: 1.9073486328125e-06 
141 mi: 1.9073486328125e-06 
142 mi: -1.9073486328125e-06 
143 mi: -9.5367431640625e-07 
144 mi: 9.5367431640625e-07 
145 mi: -0.0 
146 mi: -9.5367431640625e-07 
147 mi: -0.0 
148 mi: -9.5367431640625e-07 
149 mi: -1.9073486328125e-06 
150 mi: -0.0 
151 mi: -0.0 
152 mi: -0.0 
153 mi: 9.5367431640625e-07 
154 mi: -0.0 
155 mi: -0.0 
156 mi: -9.5367431640625e-07 
157 mi: 9.5367431640625e-07 
158 mi: -9.5367431640625e-07 
159 mi: 9.5367431640625e-07 
160 mi: -9.5367431640625e-07 
161 Traceback (most recent call last):
  File "/Users/iridium/Desktop/airlab-master/examples/affine_registration_3d.py", line 109, in <module>
    main()
  File "/Users/iridium/Desktop/airlab-master/examples/affine_registration_3d.py", line 71, in main
    registration.start()
  File "/Users/iridium/anaconda3/envs/simpleitk/lib/python3.6/site-packages/airlab-0.2.1-py3.6.egg/airlab/registration/registration.py", line 140, in start
  File "/Users/iridium/anaconda3/envs/simpleitk/lib/python3.6/site-packages/torch/optim/adam.py", line 58, in step
    loss = closure()
  File "/Users/iridium/anaconda3/envs/simpleitk/lib/python3.6/site-packages/airlab-0.2.1-py3.6.egg/airlab/registration/registration.py", line 102, in _closure
  File "/Users/iridium/anaconda3/envs/simpleitk/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/Users/iridium/anaconda3/envs/simpleitk/lib/python3.6/site-packages/airlab-0.2.1-py3.6.egg/airlab/loss/pairwise.py", line 381, in forward
RuntimeError: invalid argument 8: lda should be at least max(1, 64), but have 1 at /Users/distiller/project/conda/conda-bld/pytorch_1556653492823/work/aten/src/TH/generic/THBlas.cpp:363
RobinSandkuehler commented 5 years ago

Hi, the input data for this example is binary. Maybe this a problem for the MI loss. We will check and let you know.

MountainAndMorning commented 5 years ago

Thanks for your help. Look forward to your solution.

MountainAndMorning commented 5 years ago

Hi, the input data for this example is binary. Maybe this a problem for the MI loss. We will check and let you know.

Hi, I run this example with two real images and still encounter an error.

RobinSandkuehler commented 5 years ago

Hi, could you check the range of the intensity distribution of your input data? Maybe you need to change the sigma value of the MI loss.

huohuayuzhong commented 4 years ago

Hi, the input data for this example is binary. Maybe this a problem for the MI loss. We will check and let you know.

Hi, I run this example with two real images and still encounter an error.

I also met this and I found it's because the range of the distribution. For my case, my images were normalized to [0, 1], while the default sigma is 3, and thus the estimation of the marginal distribution became almost a uniform distribution. After I set sigma to 0.01, the problem seems solved.