2017-08-22 4 views
1

hereと表示されているように、私の質問の最後にyoutube-8mのtfレコードが保存されます。機能を抽出するコードを書きます。しかし問題がある。コードは機能内のすべての要素を正常に読み取ることができますが、feature_listsを読み取ることはできません。実際、この例にはfeatures_listはまったく含まれていないため、アクセスしようとするとエラーが発生します。どのように私はfeauures_listを読むことができます。私は、データフォーマット、私のコードおよび出力を添付:ここyoutube-8m tf-recordsのフレームレベルの機能を読む

context: { 
    feature: { 
    key : "video_id" 
    value: { 
     bytes_list: { 
     value: [YouTube video id string] 
     } 
    } 
    } 
    feature: { 
    key : "labels" 
     value: { 
     int64_list: { 
      value: [1, 522, 11, 172] # The meaning of the labels can be found here. 
     } 
     } 
    } 
} 

feature_lists: { 
    feature_list: { 
    key : "rgb" 
    value: { 
     feature: { 
     bytes_list: { 
      value: [1024 8bit quantized features] 
     } 
     } 
     feature: { 
     bytes_list: { 
      value: [1024 8bit quantized features] 
     } 
     } 
     ... # Repeated for every second of the video, up to 300 
    } 
    feature_list: { 
    key : "audio" 
    value: { 
     feature: { 
     bytes_list: { 
      value: [128 8bit quantized features] 
     } 
     } 
     feature: { 
     bytes_list: { 
      value: [128 8bit quantized features] 
     } 
     } 
    } 
    ... # Repeated for every second of the video, up to 300 
    } 

} 

はコードです:

def readTfRecordSamples(tfrecords_filename): 

    record_iterator =tf.python_io.tf_record_iterator(path=tfrecords_filename) 

    for string_record in record_iterator: 

     example = tf.train.Example() 
     example.ParseFromString(string_record) 
     prinr("Example :") 
     pprint(example) 

     img_string = (example.features) 
     print ("Features are : \n") 
     pprint(img_string) 

     classID = (example.features.feature['labels'] 
          .int64_list.value[0] 
          ) 
     videoID = (example.features.feature['video_id'] 
          .bytes_list.value[0]) 
     print (classID,videoID) 
     # Raise Error  
     rgbArray = (example.feature_lists.feature_list['rgb'] 
         .bytes_list 
         .value[0]) 

     raw_input(LineSeperator) 

とコードの出力は次のようになります。

example 
features { 
    feature { 
    key: "labels" 
    value { 
     int64_list { 
     value: 66 
     } 
    } 
    } 
    feature { 
    key: "video_id" 
    value { 
     bytes_list { 
     value: "-09K4OPZSSo" 
     } 
    } 
    } 
} 

Features are : 

feature { 
    key: "labels" 
    value { 
    int64_list { 
     value: 66 
    } 
    } 
} 
feature { 
    key: "video_id" 
    value { 
    bytes_list { 
     value: "-09K4OPZSSo" 
    } 
    } 
} 

label for -09K4OPZSSo : 66 
rgbArray = (example.feature_lists.feature_list['rgb'] 
AttributeError: 'Example' object has no attribute 'feature_lists' 

答えて

0

代わりの

example = tf.train.Example() 

try

example = tf.train.SequenceExample() 

、その後、少なくとも伝えユーチューブ-8M(それはまたfeature_listsが含まれている)と同じ構造を持っているGoogleのAudioSetデータセットで動作し、として読まれる必要がある

print(example) 

で検証シーケンス例。

関連する問題