Not sure why I'm getting this error when I'm doing:
batched_outputs = []
batched_outputs.append(output_sliced)
batched_outputs = torch.from_numpy(np.asarray(batched_outputs))
Where output_sliced
is a numpy
array.
Code seems to be working fine. Perhaps problem with your output_sliced
?
import numpy as np
import torch
batched_outputs = []
output_sliced = np.random.random((2,3))
batched_outputs.append(output_sliced)
batched_outputs = torch.from_numpy(np.asarray(batched_outputs))
I don't get any errors with the code above.
I don't know if you intended this, but do keep in mind that:
batched_outputs = []
output_sliced = np.random.random((2,3))
batched_outputs.append(output_sliced)
print(np.asarray(batched_outputs).shape)
gives you
(1, 2, 3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.