File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,10 @@ def pil_to_tensor(pic):
158
158
159
159
See :class:`~torchvision.transforms.PILToTensor` for more details.
160
160
161
+ .. note::
162
+
163
+ A deep copy of the underlying array is performed.
164
+
161
165
Args:
162
166
pic (PIL Image): Image to be converted to tensor.
163
167
@@ -174,7 +178,7 @@ def pil_to_tensor(pic):
174
178
return torch .as_tensor (nppic )
175
179
176
180
# handle PIL Image
177
- img = torch .as_tensor (np .asarray (pic ))
181
+ img = torch .as_tensor (np .array (pic , copy = True ))
178
182
img = img .view (pic .size [1 ], pic .size [0 ], len (pic .getbands ()))
179
183
# put it from HWC to CHW format
180
184
img = img .permute ((2 , 0 , 1 ))
Original file line number Diff line number Diff line change @@ -109,6 +109,10 @@ class PILToTensor:
109
109
110
110
def __call__ (self , pic ):
111
111
"""
112
+ .. note::
113
+
114
+ A deep copy of the underlying array is performed.
115
+
112
116
Args:
113
117
pic (PIL Image): Image to be converted to tensor.
114
118
You can’t perform that action at this time.
0 commit comments