readers.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:youtube-8m 作者: Tsingularity 项目源码 文件源码
def prepare_serialized_examples(self, serialized_examples):
    # set the mapping from the fields to data types in the proto
    num_features = len(self.feature_names)
    assert num_features > 0, "self.feature_names is empty!"
    assert len(self.feature_names) == len(self.feature_sizes), \
    "length of feature_names (={}) != length of feature_sizes (={})".format( \
    len(self.feature_names), len(self.feature_sizes))

    feature_map = {"video_id": tf.FixedLenFeature([], tf.string),
                   "labels": tf.VarLenFeature(tf.int64)}
    for feature_index in range(num_features):
      feature_map[self.feature_names[feature_index]] = tf.FixedLenFeature(
          [self.feature_sizes[feature_index]], tf.float32)

    features = tf.parse_example(serialized_examples, features=feature_map)
    labels = tf.sparse_to_indicator(features["labels"], self.num_classes)
    labels.set_shape([None, self.num_classes])
    ### Newly
    raw_labels = features["labels"]
    raw_coarse = tf.SparseTensor(indices = raw_labels.indices, values = tf.reshape(tf.gather(tf.constant(self.label_belongs, dtype = tf.int64), raw_labels.values), [-1]), dense_shape = raw_labels.dense_shape)
    coarse_labels = tf.sparse_to_indicator(raw_coarse, self.num_coarse_classes, name = 'coarse_transfer')
    coarse_labels.set_shape([None, self.num_coarse_classes])
    ###
    concatenated_features = tf.concat([
        features[feature_name] for feature_name in self.feature_names], 1)

    # return features["video_id"], concatenated_features, labels, tf.ones([tf.shape(serialized_examples)[0]])
    ### Newly
    return features["video_id"], concatenated_features, labels, coarse_labels, tf.ones([tf.shape(serialized_examples)[0]])
    ###
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号