pytorch / examples

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
https://pytorch.org/examples
BSD 3-Clause "New" or "Revised" License
22.38k stars 9.53k forks source link

used onnx wrong #940

Open Chenhait opened 2 years ago

Chenhait commented 2 years ago

i tried to use onnx model, but there is a wrong, thank you if any advance. python neural_style/neural_style.py eval --content-image images/content-images/amber.jpg --model saved_models/candy.onnx --output-image aa.jpg --cuda 1

first, there is a wrong, TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. i changed inp = {model.graph.input[0].name: content_image.numpy()} to inp = {model.graph.input[0].name: content_image.cpu().numpy()}

then, there is another wrong

Traceback (most recent call last):
  File "neural_style/neural_style.py", line 240, in <module>
    main()
  File "neural_style/neural_style.py", line 236, in main
    stylize(args)
  File "neural_style/neural_style.py", line 134, in stylize
    output = stylize_onnx_caffe2(content_image, args)
  File "neural_style/neural_style.py", line 167, in stylize_onnx_caffe2
    c2_out = prepared_backend.run(inp)[0]
  File "/home/tt/anaconda3/envs/gonnx/lib/python3.8/site-packages/onnx_caffe2/backend_rep.py", line 31, in run
    with core.NameScope(self._name_scope):
  File "/home/tt/anaconda3/envs/gonnx/lib/python3.8/site-packages/onnx_caffe2/backend_rep.py", line 23, in _name_scope
    return 'gpu_{}'.format(self.predict_net.device_option.cuda_gpu_id)
AttributeError: cuda_gpu_id
msaroufim commented 1 year ago

Sorry for the super late response but for ssupport requests you might get a faster answer on https://discuss.pytorch.org/