datapreprocess/tfrecord.py
def _decode_record(record, name_to_features, label, mode):
            """Decodes a record to a TensorFlow example."""
            example = tf.parse_single_example(record, name_to_features)
            # tf.Example only supports tf.int64, but the TPU only supports tf.int32.
            # So cast all int64 to int32.
            for name in list(example.keys()):
                t = example[name]
                if t.dtype == tf.int64:
                    t = tf.to_int32(t)
                example[name] = t
            if mode == tf.estimator.ModeKeys.TRAIN or mode == tf.estimator.ModeKeys.EVAL:
                split_label = example.pop(label)
                return example, split_label
                # 如果需要把feature和label分开，需要从这里入手
    
            elif mode == tf.estimator.ModeKeys.PREDICT:
                if label is not None:
                    example.pop(label)
                return example

            else:
                raise ValueError('未知mode %s' % mode)
Decodes a record to a TensorFlow example.
Decodes a record to a TensorFlow example.
Decodes a record to a TensorFlow example .
def _decode_record(record, name_to_features, label, mode):
            example = tf.parse_single_example(record, name_to_features)
            for name in list(example.keys()):
                t = example[name]
                if t.dtype == tf.int64:
                    t = tf.to_int32(t)
                example[name] = t
            if mode == tf.estimator.ModeKeys.TRAIN or mode == tf.estimator.ModeKeys.EVAL:
                split_label = example.pop(label)
                return example, split_label
            elif mode == tf.estimator.ModeKeys.PREDICT:
                if label is not None:
                    example.pop(label)
                return example
            else:
                raise ValueError('未知mode %s' % mode)
def _decode_record ( record , name_to_features , label , mode ) : example = tf . parse_single_example ( record , name_to_features ) for name in list ( example . keys ( ) ) : t = example [ name ] if t . dtype == tf . int64 : t = tf . to_int32 ( t ) example [ name ] = t if mode == tf . estimator . ModeKeys . TRAIN or mode == tf . estimator . ModeKeys . EVAL : split_label = example . pop ( label ) return example , split_label elif mode == tf . estimator . ModeKeys . PREDICT : if label is not None : example . pop ( label ) return example else : raise ValueError ( '未知mode %s' % m d )
Decodes a record to a TensorFlow example.
Decodes a record to a TensorFlow example .
"""Decodes a record to a TensorFlow example.""" # tf.Example only supports tf.int64, but the TPU only supports tf.int32. # So cast all int64 to int32. # 如果需要把feature和label分开，需要从这里入手
record
name_to_features
label
mode