Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

deep learning - does tensor label for loss calculation in crossentropy must has dtype? why my obejct has no dtype?

I created a custom dataset, and I'm wondering why the answer object has no data type?

the dataloader singel output:

{'answer': tensor([1]),
 'image': tensor([[[0.0000, 0.6180, 0.0000,  ..., 0.0000, 0.0000, 0.0000]]],
        device='cuda:0'),
 'question': tensor([[   3,    6,    8, 1274,  593,    0,    0,    0,    0,    0,    0,    0,
             0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
             0,    0,    0,    0,    0,    0]], dtype=torch.int32)}

the custom dataset:

class VQAdataset(Dataset):

    def __init__(self,img_data,  que_data, ans_data, top_1000_answers):
        
        self.que_data=que_data
        self.ans_data=ans_data
        self.img_data=img_data
        self.top_answers=top_1000_answers
       

    def __getitem__(self,index):
        if torch.is_tensor(index):
            index = index.tolist()
        question_item=self.que_data[index]
        answer_item=self.ans_data[index]
        answer_item_index=torch.tensor(self.top_answers.index(answer_item),dtype=torch.int64)           
        image_item=self.img_data[index]
        example={'image': image_item, 'question': question_item, 'answer': answer_item_index}
     
         
      
        return example

    def __len__(self):
      return len(self.que_data) 

Does the data type attribute important to the loss calculation?

question from:https://stackoverflow.com/questions/65841893/does-tensor-label-for-loss-calculation-in-crossentropy-must-has-dtype-why-my-ob

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...