File tree 2 files changed +9
-7
lines changed 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -523,10 +523,11 @@ def ensure_torch_and_prune_meta(
523
523
By default, a `MetaTensor` is returned.
524
524
However, if `get_track_meta()` is `False`, a `torch.Tensor` is returned.
525
525
"""
526
- img = convert_to_tensor (im ) # potentially ascontiguousarray
526
+ tracking_meta = get_track_meta () and meta is not None
527
+ img = convert_to_tensor (im , track_meta = tracking_meta ) # potentially ascontiguousarray
527
528
528
529
# if not tracking metadata, return `torch.Tensor`
529
- if not get_track_meta () or meta is None :
530
+ if not tracking_meta :
530
531
return img
531
532
532
533
# remove any superfluous metadata.
@@ -540,7 +541,7 @@ def ensure_torch_and_prune_meta(
540
541
meta = monai .transforms .DeleteItemsd (keys = pattern , sep = sep , use_re = True )(meta )
541
542
542
543
# return the `MetaTensor`
543
- return MetaTensor ( img , meta = meta )
544
+ return img . copy_meta_from ( meta )
544
545
545
546
def __repr__ (self ):
546
547
"""
Original file line number Diff line number Diff line change @@ -170,6 +170,8 @@ def track_transform_tensor(
170
170
171
171
if not (get_track_meta () and transform_info and transform_info .get (TraceKeys .TRACING )):
172
172
if isinstance (data , Mapping ):
173
+ if not isinstance (data , dict ):
174
+ data = dict (data )
173
175
data [key ] = data_t .copy_meta_from (out_obj ) if isinstance (data_t , MetaTensor ) else data_t
174
176
return data
175
177
return out_obj # return with data_t as tensor if get_track_meta() is False
@@ -202,15 +204,14 @@ def track_transform_tensor(
202
204
else :
203
205
out_obj .push_applied_operation (info )
204
206
if isinstance (data , Mapping ):
207
+ if not isinstance (data , dict ):
208
+ data = dict (data )
205
209
if isinstance (data_t , MetaTensor ):
206
210
data [key ] = data_t .copy_meta_from (out_obj )
207
211
else :
208
- # If this is the first, create list
209
212
x_k = TraceableTransform .trace_key (key )
210
213
if x_k not in data :
211
- if not isinstance (data , dict ):
212
- data = dict (data )
213
- data [x_k ] = []
214
+ data [x_k ] = [] # If this is the first, create list
214
215
data [x_k ].append (info )
215
216
return data
216
217
return out_obj
You can’t perform that action at this time.
0 commit comments