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 @@ -156,6 +156,10 @@ def pil_to_tensor(pic):
156156
157157 See :class:`~torchvision.transforms.PILToTensor` for more details.
158158
159+ .. note::
160+
161+ A deep copy of the underlying array is performed.
162+
159163 Args:
160164 pic (PIL Image): Image to be converted to tensor.
161165
@@ -172,7 +176,7 @@ def pil_to_tensor(pic):
172176 return torch .as_tensor (nppic )
173177
174178 # handle PIL Image
175- img = torch .as_tensor (np .asarray (pic ))
179+ img = torch .as_tensor (np .array (pic , copy = True ))
176180 img = img .view (pic .size [1 ], pic .size [0 ], len (pic .getbands ()))
177181 # put it from HWC to CHW format
178182 img = img .permute ((2 , 0 , 1 ))
Original file line number Diff line number Diff line change @@ -142,6 +142,10 @@ class PILToTensor:
142142
143143 def __call__ (self , pic ):
144144 """
145+ .. note::
146+
147+ A deep copy of the underlying array is performed.
148+
145149 Args:
146150 pic (PIL Image): Image to be converted to tensor.
147151
You can’t perform that action at this time.
0 commit comments