pytorch 踩坑记录

发布时间 2023-12-18 11:49:46作者: PengPanda

arr = arr.astypr(numpy.int16)
tensor = torch.from_numpy(arr)

  • TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.
  • 解决方法:加个arr = arr/1.0
arr = arr.astypr(numpy.int16)
arr = arr/1.0
tensor = torch.from_numpy(arr)