{"action":"created","issue":{"url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/93","repository_url":"https://api.github.com/repos/chenyuntc/pytorch-book","labels_url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/93/comments","events_url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/93/events","html_url":"https://github.com/chenyuntc/pytorch-book/issues/93","id":360185139,"node_id":"MDU6SXNzdWUzNjAxODUxMzk=","number":93,"title":"第十章图像描述中model.py和main.py的问题","user":{"login":"Canadalynx","id":38777727,"node_id":"MDQ6VXNlcjM4Nzc3NzI3","avatar_url":"https://avatars1.githubusercontent.com/u/38777727?v=4","gravatar_id":"","url":"https://api.github.com/users/Canadalynx","html_url":"https://github.com/Canadalynx","followers_url":"https://api.github.com/users/Canadalynx/followers","following_url":"https://api.github.com/users/Canadalynx/following{/other_user}","gists_url":"https://api.github.com/users/Canadalynx/gists{/gist_id}","starred_url":"https://api.github.com/users/Canadalynx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Canadalynx/subscriptions","organizations_url":"https://api.github.com/users/Canadalynx/orgs","repos_url":"https://api.github.com/users/Canadalynx/repos","events_url":"https://api.github.com/users/Canadalynx/events{/privacy}","received_events_url":"https://api.github.com/users/Canadalynx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-14T07:18:52Z","updated_at":"2018-09-16T09:18:15Z","closed_at":null,"author_association":"NONE","body":"我跑了main.py之后 \r\n # 可视化原始图片 + 可视化人工的描述语句\r\n                raw_img = _data['ix2id'][indexes[0]]\r\n                img_path = opt.img_path + raw_img\r\n                raw_img = Image.open(img_path).convert('RGB')\r\n                raw_img = tv.transforms.ToTensor()(raw_img)\r\n\r\n                raw_caption = captions.data[:, 0]\r\n                raw_caption = ''.join([_data['ix2word'][ii] for ii in raw_caption])\r\n                vis.text(raw_caption, u'raw_caption')\r\n                vis.img('raw', raw_img, caption=raw_caption)\r\n\r\n                # 可视化网络生成的描述语句\r\n                results = model.generate(imgs.data[0])\r\n                vis.text('</br>'.join(results), u'caption')\r\n\r\n以上部分的下面这两句\r\n` raw_caption = captions.data[:, 0]`\r\n` raw_caption = ''.join([_data['ix2word'][ii] for ii in raw_caption])`\r\n               \r\n报错keyerror 我去网上搜了，只有类似问题，不过看起来是数据类型的问题 应该是因为ii想读的是标量，结果读到一个tensor？反正半懂不懂的我把它改成了\r\n`raw_caption = t.tensor(captions.data[:, 0],device='cpu').numpy()`             \r\n然后model.py的以下部分（原文第59，60行）又报错，应该还是同样的问题\r\n`sentences, score = cap_gen.beam_search(img)`\r\n`sentences = [' '.join([self.ix2word[idx] for idx in sent])\r\n                     for sent in sentences]`\r\n我在这两句之间改成了\r\n```\r\nsentences, score = cap_gen.beam_search(img)\r\n        sentences1=[]\r\n        for i in range(len(sentences)):\r\n                 sentences1.append([])\r\n                 for ii in sentences[i]:\r\n                          a=ii.item()\r\n                          sentences1[i].append(a)\r\nsentences = [' '.join([self.ix2word[idx] for idx in sent]) for sent in sentences1]\r\n```\r\n结果跑通了，但是觉得大佬们肯定有更理论的解释和更高明的方法，希望大佬们指点下我这个菜鸡\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/comments/421729838","html_url":"https://github.com/chenyuntc/pytorch-book/issues/93#issuecomment-421729838","issue_url":"https://api.github.com/repos/chenyuntc/pytorch-book/issues/93","id":421729838,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTcyOTgzOA==","user":{"login":"leejincheng","id":8937353,"node_id":"MDQ6VXNlcjg5MzczNTM=","avatar_url":"https://avatars2.githubusercontent.com/u/8937353?v=4","gravatar_id":"","url":"https://api.github.com/users/leejincheng","html_url":"https://github.com/leejincheng","followers_url":"https://api.github.com/users/leejincheng/followers","following_url":"https://api.github.com/users/leejincheng/following{/other_user}","gists_url":"https://api.github.com/users/leejincheng/gists{/gist_id}","starred_url":"https://api.github.com/users/leejincheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leejincheng/subscriptions","organizations_url":"https://api.github.com/users/leejincheng/orgs","repos_url":"https://api.github.com/users/leejincheng/repos","events_url":"https://api.github.com/users/leejincheng/events{/privacy}","received_events_url":"https://api.github.com/users/leejincheng/received_events","type":"User","site_admin":false},"created_at":"2018-09-16T09:18:15Z","updated_at":"2018-09-16T09:18:15Z","author_association":"NONE","body":"直接把\r\nsentences = [' '.join([self.ix2word[idx] for idx in sent]) for sent in sentences1]\r\n改为\r\nsentences = [' '.join([self.ix2word[int(idx)] for idx in sent]) for sent in sentences1]\r\n就好了"}}
{"actor":{"display_login":"leejincheng"}}