在tensorflow中将列表列表存储为tf记录

Saf*_*aa 6 record tensorflow

在TensorFlow中的tf记录中存储/读取列表列表的最佳方法是什么?我尝试将数据序列化为一维列表,然后在读取时将其重塑为原始大小。但是,编码过程将花费很多时间。

写入tf_record:有问题的变量:(word_data形状= [nb_channels,1500])

electrodes_coordinates=word_data['electrodes_coordinates']
    electrodes_loc3=word_data['electrodes_loc3']
    nb_electrodes=word_data['nb_electrodes']
    label=word_data['label']
    word_data=word_data['word']

    #reshape word_data from list of list (nb_channel,nb_time points) to list (nb_channel*nb_timepoints)
    word_data=np.reshape(word_data, [-1])

    context = tf.train.Features(feature={
      "word/word_id": _bytes_feature(word),
      "word/nb_channels": _int64_feature(nb_electrodes),
      "word/label": _int64_feature(int(label))
    })


    feature_lists = tf.train.FeatureLists(feature_list={
      "word/electrode_x_coordinates":_float_feature_list(electrodes_coordinates[:,0]),
      "word/electrode_y_coordinates":_float_feature_list(electrodes_coordinates[:,1]),
      "word/electrode_z_coordinates":_float_feature_list(electrodes_coordinates[:,2]),
      "word/electrode_location3":_int64_feature_list(loc3_to_id(electrodes_loc3,loc3_dict)),
      "word/data": _float_feature_list(word_data)})

    sequence_example = tf.train.SequenceExample(context=context ,feature_lists=feature_lists)

    return sequence_example
Run Code Online (Sandbox Code Playgroud)

从阅读tf_record

context, sequence = tf.parse_single_sequence_example(serialized,
        context_features={
        nb_channels: tf.FixedLenFeature([], dtype=tf.int64),
        label: tf.FixedLenFeature([], dtype=tf.int64)
        },

        sequence_features={
        electrode_x_coordinates: tf.FixedLenSequenceFeature([], dtype=tf.float32),
        electrode_y_coordinates: tf.FixedLenSequenceFeature([], dtype=tf.float32),
        electrode_z_coordinates: tf.FixedLenSequenceFeature([], dtype=tf.float32),
        electrode_location3: tf.FixedLenSequenceFeature([], dtype=tf.int64),
        word_data: tf.FixedLenSequenceFeature([], dtype=tf.float32)
        }
        )

    encoded_nb_channels = context[nb_channels]
    encoded_label = context[label]

    encoded_electrode_x_coordinates = sequence[electrode_x_coordinates]
    encoded_electrode_y_coordinates = sequence[electrode_y_coordinates]
    encoded_electrode_z_coordinates = sequence[electrode_z_coordinates]
    encoded_electrode_location3 = sequence[electrode_location3]
    encoded_word_data = sequence[word_data]
Run Code Online (Sandbox Code Playgroud)