2017-01-12 24 views
0

如何將值列表傳遞到feature_list?文檔表明這是有效的,但是如果通過列表導致錯誤,這是如何實現的並不清楚。tf.train.SequenceExample帶有列表在每個步驟

>>> tf.train.SequenceExample().feature_lists.feature_list["multiple"].feature.add().int64_list.value.append([1,2,3,4]) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal /containers.py", line 251, in append 
    self._values.append(self._type_checker.CheckValue(value)) 
    File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal /type_checkers.py", line 132, in CheckValue 
raise TypeError(message) 
TypeError: [1, 2, 3, 4] has type <type 'list'>, but expected one of: (<type 'int'>, <type 'long'>) 

這是在示例proto文件中給出的示例。 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/example/example.proto

// Conditionally conformant FeatureLists, the parser configuration determines 
// if the feature sizes must match: 
// feature_lists: { feature_list: { 
//  key: "movie_ratings" 
//  value: { feature: { float_list: { value: [ 4.5 ] } } 
//    feature: { float_list: { value: [ 5.0, 6.0 ] } } } 
// } } 

是否需要使用其他的東西添加列表時相比,追加?

的序列的一個例子是...

[[1,2,3],[4,5],[6,7],[8,9,10]] 

...其中有在該序列的四個步驟,並且在每個步驟有一組值。理想的結果看起來像下面的例子。

feature_lists: { feature_list: { 
     key: "movie_ratings" 
     value: { feature: { float_list: { value: [ 1, 2, 3 ] } } 
       feature: { float_list: { value: [ 4, 5 ] } } 
       feature: { float_list: { value: [ 6, 7 ] } } 
       feature: { float_list: { value: [ 8, 9, 10 ] } } } 
    } } 

回答

0

使用extend而不是append。

tf.train.SequenceExample().feature_lists.feature_list["multiple"].feature.add().int64_list.value.extend([1,2,3,4]) 
相關問題