Comments (5)
@FUNCTION_REWRITER.register_rewriter(func_name='copy.deepcopy')
def copy__default(tensor: Tensor, *args, **kwargs) -> Tensor:
"""Rewrite `copy.deepcopy` for default backend.
Replace it with tensor.clone(), or may raise `NYI: Named tensors are not
supported with the tracer`
"""
ctx = FUNCTION_REWRITER.get_context()
# if isinstance(tensor, Tensor) and args == () and kwargs == {}:
if isinstance(tensor, Tensor):
return tensor.clone()
elif isinstance(tensor, dict):
# from copy import deepcopy
def deepcopy_dict(obj,memo={}):
if isinstance(obj, dict):
# 如果obj是字典,则创建新的空字典并递归拷贝其中的值
copied_obj = {}
memo[id(obj)] = copied_obj # 存储已拷贝的字典引用
for key, value in obj.items():
copied_obj[deepcopy_dict(key, memo)] = deepcopy_dict(value, memo)
return copied_obj
elif isinstance(obj, list):
# 如果obj是列表,则创建新的空列表并递归拷贝其中的元素
copied_obj = []
memo[id(obj)] = copied_obj # 存储已拷贝的列表引用
for item in obj:
copied_obj.append(deepcopy_dict(item, memo))
return copied_obj
elif isinstance(obj, set):
# 如果obj是集合,则创建新的空集合并递归拷贝其中的元素
copied_obj = set()
memo[id(obj)] = copied_obj
for item in obj:
copied_obj.add(deepcopy_dict(item, memo))
return copied_obj
elif isinstance(obj, (int, float, complex, str, bytes, tuple, frozenset, type(None))):
# 如果obj是不可变类型,则直接返回
return obj
elif id(obj) in memo:
# 如果obj已经被拷贝过,则直接返回其拷贝
return memo[id(obj)]
else:
# 对于其他类型,尝试使用copy模块的deepcopy(如果需要)
try:
# import copy
return copy__default(obj, memo)
except Exception as e:
raise TypeError(f"Unsupported type {type(obj)} in deepcopy") from e
return deepcopy_dict(tensor, *args, **kwargs)
else:
pass
return ctx.origin_func(tensor, *args, **kwargs)
from mmdeploy.
hi, sorry for the issue. This project is not actively maintained. Welcome to PR us to fix any bugs. Thanks for your understanding.
from mmdeploy.
@RunningLeon Thank you, that worked.
Colud you do a PR?
from mmdeploy.
@RunningLeon Thank you, that worked. Colud you do a PR?
这个代码没有严格经过测试,网上找的 只能做为临时方案,问题的原因是当是字典时如果不处理还是会调用对象重载的深拷贝函数导致
from mmdeploy.
@RunningLeon
I see. tha's true.
from mmdeploy.
Related Issues (20)
- Error while converting mmdet3d model to tensorRT engine
- [Bug] HOT 1
- [Bug] How to get the pred_instances for the mask2Former tensorrt model
- [Bug] rtmo tensorrt model with 1x3x1280x640 has problem while tensorrt model with 1x3x640x640 works well HOT 1
- [Bug] ModuleNotFoundError: No module named 'mmdeploy_runtime.mmdeploy_runtime'
- [Bug] MViT onnxruntime input shape does not to deployment config
- [Feature] Code update for supporting latest onnxruntime & OpenVINO HOT 1
- [Docs] Export human pose top-down relying on human detector to onnx
- [Bug] MMDeployCSharp.dll does not find a dependency on mmdeploy.dll
- [Bug] Model loading issue
- [Feature] CPU Core Utilization during GPU Model Inference Benchmark script
- segmenter infer error[Bug]
- [Bug]Build MMDeploy get wrong! HOT 2
- [Bug] Error Exporting RetinaNet for Single Class Case with CrossEntropyLoss in MMDeploy HOT 1
- [Bug] RTMDet : Error when deploying onnx/engine model using tensorRT backend configs HOT 3
- [Bug] Cannot use Tritonserver with MMdeploy custom operations
- ROIAlign plugin was not found in the plugin registry!
- [Bug] Build mmdeploy sdk for tensorrt err
- [Bug] Unable to reproduce export to CoreML in lib HOT 1
- [Docs] A100算力加持!书生大模型实战营第3期全面升级,趣味闯关模式等你开启
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmdeploy.