欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

terminate called after throwing an instance of ‘c10::IndexError‘

程序员文章站 2022-07-13 23:53:10
...

terminate called after throwing an instance of 'c10::IndexError'
  what():  select(): index 3 out of range for tensor of size [3] at dimension 0 (select at ../aten/src/ATen/native/TensorShape.cpp:765)
  frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6a (0x7fc09b944aaa in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libc10.so)
frame #1: at::native::select(at::Tensor const&, long, long) + 0x3fc (0x7fc08bdaafcc in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libtorch_cpu.so)
frame #2: <unknown function> + 0x12269dd (0x7fc08c0d79dd in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libtorch_cpu.so)
frame #3: <unknown function> + 0x120ddb7 (0x7fc08c0bedb7 in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0x2beb918 (0x7fc08da9c918 in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0x120ddb7 (0x7fc08c0bedb7 in /opt/libtorch-cxx11-abi-shared-with-deps-1.5.0/libtorch/lib/libtorch_cpu.so)
frame #6: at::Tensor c10::KernelFunction::callUnboxed<at::Tensor, at::Tensor const&, long, long>(c10::OperatorHandle const&, at::Tensor const&, long, long) const + 0xd5 (0x55e69fa3676d in ./example-app)
frame #7: at::Tensor c10::Dispatcher::callUnboxedWithDispatchKey<at::Tensor, at::Tensor const&, long, long>(c10::OperatorHandle const&, c10::DispatchKey, at::Tensor const&, long, long) const + 0xc1 (0x55e69fa2f23b in ./example-app)
frame #8: at::Tensor c10::Dispatcher::callUnboxed<at::Tensor, at::Tensor const&, long, long>(c10::OperatorHandle const&, at::Tensor const&, long, long) const + 0xbb (0x55e69fa2660f in ./example-app)
frame #9: at::Tensor c10::OperatorHandle::callUnboxed<at::Tensor, at::Tensor const&, long, long>(at::Tensor const&, long, long) const + 0x7e (0x55e69fa1b7ca in ./example-app)
frame #10: at::Tensor::select(long, long) const + 0xa5 (0x55e69fa0d525 in ./example-app)
frame #11: at::Tensor::operator[](long) const + 0x3f (0x55e69fa0ee9f in ./example-app)
frame #12: main + 0x66c (0x55e69fa01274 in ./example-app)
frame #13: __libc_start_main + 0xe7 (0x7fc048536b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #14: _start + 0x2a (0x55e69f9fec1a in ./example-app)

已放弃 (核心已转储)

解决方案
将这段代码里面的10改为2

float score = scores[10].item().toFloat();

float score = scores[2].item().toFloat();