Closed CensorKo closed 2 years ago
Can you try use python to run your torch script model? What's the expected input shapes?
Build like this: Pipeline pipeline = new Pipeline(); pipeline.add(new Resize(640, 640)); pipeline.add(new ToTensor());
Translator<Image, DetectedObjects> translator = YoloV5Translator.builder().setPipeline(pipeline)
.optSynsetArtifactName("coco.names").optThreshold(0.5f).build();
new Resize(640, 640) Set and export size the same
Description
First, I export my model from yolov5.
export command: python export.py --weights ./runs/train/exp26/weights/best.pt --img 640 --batch 1 --include torchscript
And then my djl code is: Translator<Image, DetectedObjects> translator = YoloV5Translator.builder().optSynsetArtifactName("coco.names").build(); Criteria<Image, DetectedObjects> criteria = Criteria.builder() .setTypes(Image.class, DetectedObjects.class) .optDevice(Device.cpu()) .optModelUrls(Main.class.getResource("/yolov5s").getPath()) .optModelName("best.torchscript.pt") .optTranslator(translator) .optEngine("PyTorch") .build();
when execute: ZooModel<Image, DetectedObjects> model = ModelZoo.loadModel(criteria); Got errors.
Error Message
[W TensorImpl.h:1156] Warning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (function operator()) ai.djl.translate.TranslateException: ai.djl.engine.EngineException: The following operation failed in the TorchScript interpreter. Traceback of TorchScript, serialized code (most recent call last): File "code/torch/models/yolo.py", line 46, in forward _35 = (_4).forward(_34, ) _36 = (_2).forward((_3).forward(_35, ), _29, ) _37 = (_0).forward(_33, _35, (_1).forward(_36, ), )