cs231n'18: Assignment 3 | RNN Captioning

Assignment3 | RNN Captioning

这部分实际上做了两件事情,首先建立一个 RNN,然后以此 RNN 为基础,训练一个模型来完成图片 caption 的工作。我感觉作业中的代码先后顺序有些混乱,这里依照自己的理解,把内容重新组织一下。

Dataset

train 和 val 使用的是 Coco2014,从打印出来的 data 信息来大概浏览一下数据的构成。

train_captions <class 'numpy.ndarray'> (400135, 17) int32
train_image_idxs <class 'numpy.ndarray'> (400135,) int32
train_features <class 'numpy.ndarray'> (82783, 512) float32
idx_to_word <class 'list'> 1004
word_to_idx <class 'dict'> 1004
train_urls <class 'numpy.ndarray'> (82783,) <U63

train dataset 中有 82783 张图片,每一张图片对应多个 caption,共有 400135 个caption,每一个 caption 最多包含 17 个整形数字,每一个数字通过 idx_to_word 对应到一个单词。idx_to_word 是一个 list,每一个位置上对应一个单词,其中位置0-3分别是特殊字符 \, \,\,\。所有的 caption 都是以 \ 起,以 \ 止,如果不足17个单词,那么在 \ 以后补 \,不在 idx_to_word 中的记为 \。

print(data['train_captions'][1])
print(decode_captions(data['train_captions'][1], data['idx_to_word']))
[  1   4   3 172   6   4  62  10 317   6 114 612   2   0   0   0   0]
<START> a <UNK> view of a kitchen and all of its appliances <END>

train feature 是直接取自 VGG16 的第 fc7 层,也就是从 4096 映射到 1000 个 class 的前一层,所以是 4096 维的。这里为了减少计算量,使用 PCA 将维度减小到 512 维。

Vanilla RNN

CNN_time_cap
RNN 一次处理一个长度为 T 的时间序列 x(0), x(t), … , x(T),其中,隐状态 h(t) 由该时刻输入 x(t) 和上一时刻隐状态 h(t-1) 共同决定:

h(t)=tg(Wxx(t)+Whh(t1)+bh) h ( t ) = t g ( W x ⋅ x ( t ) + W h ⋅ h ( t − 1 ) + b h )

输出的 score 由该时刻的隐状态 h(t) 决定:
s(t)=Wh
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值