x= x.cpu() in retrival.py (around line 636)get error with nontype
Chaoran-F opened this issue · 0 comments
Chaoran-F commented
I printed x after the for image, label in dataloader: line and the for loop line were completed, and I got the result of None, and I found that for image, label in dataloader: did not start the loop, so what is the reason, I Try to check the dataloader, there is an output, but the for loop is not started.
error:
x = x.cpu()
AttributeError: 'NoneType' object has no attribute 'cpu'
code:
print('dataset_this_rank',dataset_this_rank)
dataloader = DataLoader(dataset_this_rank, **kwargs)
x = None
y_np = []
idx = 0
print('dataloader',dataloader)
print('before: ', x)
for image, label in dataloader:
print('entry!')
image = image.cuda()
embedding = model(image)
embedding_size: int = embedding.size(1)
if x is None:
print(x)
size = [len(dataset_this_rank), embedding_size]
x = torch.zeros(*size, device=image.device)
print('!',x)
x[idx:idx + embedding.size(0)] = embedding
y_np.append(np.array(label))
idx += embedding.size(0)
print('after: ', x)
x = x.cpu()
dataset: own food dataset, use sop loading style
envs: torch:1.12.1,cuda:11.4