@@ -169,13 +169,35 @@ def test_ndarray_to_pil_image(self):
169
169
l , = img .split ()
170
170
assert np .allclose (l , img_data [:, :, 0 ])
171
171
172
- def test_ndarray16_to_pil_image (self ):
172
+ def test_ndarray_bad_types_to_pil_image (self ):
173
173
trans = transforms .ToPILImage ()
174
- img_data = np .random .randint (0 , 65535 , [4 , 4 , 1 ], np .uint16 )
174
+ with self .assertRaises (AssertionError ):
175
+ trans (np .ones ([4 , 4 , 1 ], np .int64 ))
176
+ trans (np .ones ([4 , 4 , 1 ], np .uint16 ))
177
+ trans (np .ones ([4 , 4 , 1 ], np .uint32 ))
178
+ trans (np .ones ([4 , 4 , 1 ], np .float64 ))
179
+
180
+ def test_ndarray_gray_float32_to_pil_image (self ):
181
+ trans = transforms .ToPILImage ()
182
+ img_data = torch .FloatTensor (4 , 4 , 1 ).random_ ().numpy ()
183
+ img = trans (img_data )
184
+ assert img .mode == 'F'
185
+ assert np .allclose (img , img_data [:, :, 0 ])
186
+
187
+ def test_ndarray_gray_int16_to_pil_image (self ):
188
+ trans = transforms .ToPILImage ()
189
+ img_data = torch .ShortTensor (4 , 4 , 1 ).random_ ().numpy ()
175
190
img = trans (img_data )
176
191
assert img .mode == 'I;16'
177
192
assert np .allclose (img , img_data [:, :, 0 ])
178
193
194
+ def test_ndarray_gray_int32_to_pil_image (self ):
195
+ trans = transforms .ToPILImage ()
196
+ img_data = torch .IntTensor (4 , 4 , 1 ).random_ ().numpy ()
197
+ img = trans (img_data )
198
+ assert img .mode == 'I'
199
+ assert np .allclose (img , img_data [:, :, 0 ])
200
+
179
201
180
202
if __name__ == '__main__' :
181
203
unittest .main ()
0 commit comments