このサイトのチュートリアルを学習していたら、以下のようなエラーが吐き出された。
mscoco = json.load(open('annotations/captions_train2014.json'))
captionStrings = ['[START] ' + entry['caption'].encode('ascii') for entry in mscoco['annotations']]
print('Number of sentences', len(captionStrings))
print('First sentence in the list', captionStrings[0])
a = [entry['caption'].encode('ascii') for entry in mscoco['annotations']]
print(a[0])
この場合、.encode(‘ascii’)を取り去ればstrに変換される。というかbytesに変換されない。
a = [entry['caption'] for entry in mscoco['annotations']]
print(a[0])
mscoco = json.load(open('annotations/captions_train2014.json'))
captionStrings = ['[START] ' + entry['caption'] for entry in mscoco['annotations']]
print('Number of sentences', len(captionStrings))
print('First sentence in the list', captionStrings[0])
恐らくはpython2とpython3の違いかと思われる。
スポンサーリンク
スポンサーリンク