Open samyeh0527 opened 3 years ago
Use Tensor.cpu() to cpoy the tensor to host memory first.
Traceback (most recent call last):
File "/home/umeida/Desktop/yolor/train.py", line 537, in
File "/home/umeida/anaconda3/envs/yolor/lib/python3.9/site-packages/torch/_tensor.py", line 643, in array
return self.numpy() <-------Replace Tensor.cpu() ?
return np.array(targets.cpu())
return np.array(targets.cpu())
AttributeError: 'list' object has no attribute 'cpu'
@WongKinYiu in this code https://github.com/WongKinYiu/yolor/commit/840e56e86e69692c6c1cac1a32caf1c59ff6dbba run to code,
ValurError
Traceback (most recent call last):
File "test.py", line 332, in
why in yolor/utils/plots.py
def output_to_target(output, width, height):
output is list.
[tensor([[2.29000e+02, 2.24375e+02, 7.82500e+02, 6.96000e+02, 9.19922e-01, 0.00000e+00], [2.27500e+02, 2.24500e+02, 7.80500e+02, 6.95000e+02, 7.84302e-02, 1.00000e+00], [2.15500e+02, 2.26875e+02, 7.83500e+02, 6.94500e+02, 4.02832e-03, 7.00000e+00], [3.29375e+01, 1.65375e+02, 7.09375e+01, 2.31125e+02, 3.62396e-03, 7.00000e+00], [2.28250e+02, 2.25000e+02, 7.80000e+02, 6.98000e+02, 2.83051e-03, 9.00000e+00], [2.11500e+02, 1.03800e+03, 2.49000e+02, 1.05600e+03, 2.40517e-03, 0.00000e+00], [2.28250e+02, 2.25000e+02, 7.80000e+02, 6.98000e+02, 1.37711e-03, 6.00000e+00], [2.11375e+02, 1.03800e+03, 2.49375e+02, 1.05600e+03, 1.21403e-03, 7.00000e+00]], device='cuda:0'), ..... ..... ]
this output len is 32, not in if instance(output, torch.Tensor) so, i modify output = output.cpu() -> AttributeError: 'list' object has no attribute 'cpu'
and, i modify output = output.cpu().numpy() -> AttributeError: 'list' object has no attribute 'cpu'
and i modify output = output[0].cpu().numpy -> AttributeError: 'numpy.float32' object has no attribute 'cpu' python test.py --data data/coco.yaml --img 1024 --batch 1 --conf 0.001 --iou 0.5 --device 0 --cfg cfg/yolor_p6.cfg --weights runs/train/yolor_p658/weights/best_ap50.pt --name yolor_p6_val
why in function output is type list?
Thanks , I change the 840e56e can fix this issue . it's work successful
Is there any reason this change isn't being merged to the main branches?
may be just rarely happens
ı have same error, but ı dont solution error can you halp me?
def dist(args, model, device, train_loader, fea_loader, tar_loader, centers): model.eval() dizi=[] d0 = [] d1 = [] d2 = [] d3 = []
mean_d0 = 0
mean_d1 = 0
mean_d2 = 0
mean_d3 = 0
var_d0 = 0
var_d1 = 0
var_d2 = 0
var_d3 = 0
with torch.no_grad():
for batch_idx, data in enumerate(train_loader):
sample = data[:, 0:784]
#print("sample:{}".format(sample))
target = data[:, 784:785]
#print("target:{}".format(target))
sample = sample.reshape((-1, 1, 28, 28))
#print("sample:{}".format(sample))
sample = Variable(torch.from_numpy(sample))
#print("sample:{}".format(sample))
sample = sample.cuda()
# print("sample:{}".format(sample))
sample = sample.type(torch.cuda.FloatTensor)
#print("sample:{}".format(sample))
target = Variable(torch.from_numpy(target))
#print("target:{}".format(target))
target = target.view(64)
#print("target:{}".format(target))
target = target.cuda()
#print("target:{}".format(target))
target = target.type(torch.cuda.LongTensor)
#print("target:{}".format(target))
fea, output = model(sample) #[64,2]
#print("fea:{}".format(fea))
fea_loader.append(fea)
#print("fea_loader:{}".format(fea_loader))
tar_loader.append(target)
#print("tar_loader:{}".format(fea_loader))
expanded_centers = centers.expand(64, -1, -1) # [64,4,2]
# print("expanded_centers:{}".format(expanded_centers))
expanded_feature = fea.expand(4, -1, -1).transpose(1, 0) # [64,4,2]
#print("expanded_feature:{}".format(expanded_feature))
distance_centers = (expanded_feature - expanded_centers).pow(2).sum(dim=-1) # [64,4]
#print("distance_centers:{}".format(distance_centers))
for i in range(0, 64):
if target[i]==0:
d0.append(distance_centers[i,0]**0.5)
if target[i]==1:
d1.append(distance_centers[i,1]**0.5)
if target[i]==2:
d2.append(distance_centers[i,2]**0.5)
if target[i]==3:
d3.append(distance_centers[i,3]**0.5)
#print(len(d0))
mean_d0 = np.mean(d0) #i am getting the error here
mean_d1 = np.mean(d1)
mean_d2 = np.mean(d2)
mean_d3 = np.mean(d3)
var_d0 = np.std(d0)
var_d1 = np.std(d1)
var_d2 = np.std(d2)
var_d3 = np.std(d3)
return mean_d0,mean_d1,mean_d2,mean_d3,var_d0,var_d1,var_d2,var_d3
Hi WongKinYiu , when training is the end will show some issues but my environment python is [3.9] didn't know the version difference is the main reason for this .
As just mentioned Error issues [ can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to cpoy the tensor to host memory first ]
I know the numpy is cpu only but how can i fix this issues ?
wish you a nice day