东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 2537|回复: 0
打印 上一主题 下一主题

[课堂笔记] 05、项目相关数据flickr30k介绍与词表生成_笔记

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14435
QQ
跳转到指定楼层
楼主
发表于 2019-5-15 10:35:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


05、项目相关数据flickr30k介绍与词表生成_笔记


训练数据flickr30k(已标注好的图像)下载:链接:https://pan.baidu.com/s/1ola0honCkwPLdV4DW0TGsg
提取码:eggh


预训练好的Inception CNN神经网络数据下载:链接:https://pan.baidu.com/s/1rHivh5dlG6yevwCmY19Y6w
提取码:5ter

  1. # -*- coding: utf-8 -*-
  2. __author__ = u'东方耀 微信:dfy_88888'
  3. __date__ = '2019/5/15 11:30'
  4. __product__ = 'PyCharm'
  5. __filename__ = 'generate_vocab'


  6. import pprint

  7. input_description_file = './results_20130124.token'
  8. output_vocab_file = './vocab.txt'


  9. def count_vocab(input_description_file):
  10.     with open(input_description_file, 'r', encoding='utf-8') as f:
  11.         lines = f.readlines()
  12.     max_length_of_sentences = 0
  13.     # key: 句子长度 value: 长度的次数
  14.     length_dict = {}
  15.     # key: 词  value: 词频
  16.     vocab_dict = {}
  17.     for line in lines:
  18.         image_id, description = line.strip('\n').split('\t')
  19.         words = description.strip(' ').split()
  20.         max_length_of_sentences = max(max_length_of_sentences, len(words))
  21.         length_dict.setdefault(len(words), 0)
  22.         length_dict[len(words)] += 1

  23.         for word in words:
  24.             vocab_dict.setdefault(word, 0)
  25.             vocab_dict[word] += 1
  26.     print('max_length_of_sentences: %d' % max_length_of_sentences)
  27.     pprint.pprint(length_dict)

  28.     return vocab_dict


  29. vocab_dict = count_vocab(input_description_file)

  30. sorted_vocab_dict = sorted(vocab_dict.items(), key=lambda d: d[1], reverse=True)


  31. with open(output_vocab_file, 'w', encoding='utf-8') as f:
  32.     f.write('<UNK>\t99999999999999999\n')
  33.     for item in sorted_vocab_dict:
  34.         f.write('%s\t%d\n' % (item[0], item[1]))



复制代码









让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-29 20:39 , Processed in 0.173110 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表