TensorFlow用于描述输入数据的协议消息的机器学习示例

2018-09-27 17:23 更新

//用于描述输入数据的协议消息机器学习示例

//模型训练或推理.

syntax = "proto3"; import "tensorflow/core/example/feature.proto"; option cc_enable_arenas = true; option java_outer_classname = "ExampleProtos"; option java_multiple_files = true; option java_package = "org.tensorflow.example"; package tensorflow;

//一个例子是用于存储数据的大多数归一化的数据格式

//训练和推理.它包含一个键值存储(特征); 

//每个键(字符串)映射到一个Feature消息(这是一个打包BytesList,

// FloatList或Int64List).这种灵活和紧凑的格式允许

//存储大量的类型数据,但要求数据形状

//并使用由用于的配置文件和解析器确定

//读取和写入此格式.也就是说,这个例子主要不是

//自描述格式.在TensorFlow中,示例是以行为主的读取

//格式,所以任何描述具有2级或更高级别的数据的配置

//应该记住这一点.例如,为了存储一个M×N字节的矩阵,

// BytesList 必须包含M * N个字节,M行N个连续值,

//每个,也就是说,BytesList 值必须将矩阵存储为:

// .... row 0 .... .... row 1 .... // ........... // ... row M-1 ....

//

//电影推荐应用程序的示例:

// features { // feature { // key: "age" // value { float_list { // value: 29.0 // }} // } // feature { // key: "movie" // value { bytes_list { // value: "The Shawshank Redemption" // value: "Fight Club" // }} // } // feature { // key: "movie_ratings" // value { float_list { // value: 9.0 // value: 9.7 // }} // } // feature { // key: "suggestion" // value { bytes_list { // value: "Inception" // }} // } // # Note that this feature exists to be used as a label in training. // # E.g., if training a logistic regression model to predict purchase // # probability in our learning tool we would set the label feature to // # "suggestion_purchased". // feature { // key: "suggestion_purchased" // value { float_list { // value: 1.0 // }} // } // # Similar to "suggestion_purchased" above this feature exists to be used // # as a label in training. // # E.g., if training a linear regression model to predict purchase // # price in our learning tool we would set the label feature to // # "purchase_price". // feature { // key: "purchase_price" // value { float_list { // value: 9.99 // }} // } // } // // A conformant Example data set obeys the following conventions: // - If a Feature K exists in one example with data type T, it must be of // type T in all other examples when present. It may be omitted. // - The number of instances of Feature K list data may vary across examples, // depending on the requirements of the model. // - If a Feature K doesn't exist in an example, a K-specific default will be // used, if configured. // - If a Feature K exists in an example but contains no items, the intent // is considered to be an empty tensor and no default will be used. message Example { Features features = 1; }; // A SequenceExample is an Example representing one or more sequences, and // some context. The context contains features which apply to the entire // example. The feature_lists contain a key, value map where each key is // associated with a repeated set of Features (a FeatureList). // A FeatureList thus represents the values of a feature identified by its key // over time / frames. // // Below is a SequenceExample for a movie recommendation application recording a // sequence of ratings by a user. The time-independent features ("locale", // "age", "favorites") describing the user are part of the context. The sequence // of movies the user rated are part of the feature_lists. For each movie in the // sequence we have information on its name and actors and the user's rating. // This information is recorded in three separate feature_list(s). // In the example below there are only two movies. All three feature_list(s), // namely "movie_ratings", "movie_names", and "actors" have a feature value for // both movies. Note, that "actors" is itself a bytes_list with multiple // strings per movie. // // context: { // feature: { // key : "locale" // value: { // bytes_list: { // value: [ "pt_BR" ] // } // } // } // feature: { // key : "age" // value: { // float_list: { // value: [ 19.0 ] // } // } // } // feature: { // key : "favorites" // value: { // bytes_list: { // value: [ "Majesty Rose", "Savannah Outen", "One Direction" ] // } // } // } // } // feature_lists: { // feature_list: { // key : "movie_ratings" // value: { // feature: { // float_list: { // value: [ 4.5 ] // } // } // feature: { // float_list: { // value: [ 5.0 ] // } // } // } // } // feature_list: { // key : "movie_names" // value: { // feature: { // bytes_list: { // value: [ "The Shawshank Redemption" ] // } // } // feature: { // bytes_list: { // value: [ "Fight Club" ] // } // } // } // } // feature_list: { // key : "actors" // value: { // feature: { // bytes_list: { // value: [ "Tim Robbins", "Morgan Freeman" ] // } // } // feature: { // bytes_list: { // value: [ "Brad Pitt", "Edward Norton", "Helena Bonham Carter" ] // } // } // } // } // } // // A conformant SequenceExample data set obeys the following conventions: // // Context: // - All conformant context features K must obey the same conventions as // a conformant Example's features (see above). // Feature lists: // - A FeatureList L may be missing in an example; it is up to the // parser configuration to determine if this is allowed or considered // an empty list (zero length). // - If a FeatureList L exists, it may be empty (zero length). // - If a FeatureList L is non-empty, all features within the FeatureList // must have the same data type T. Even across SequenceExamples, the type T // of the FeatureList identified by the same key must be the same. An entry // without any values may serve as an empty feature. // - If a FeatureList L is non-empty, it is up to the parser configuration // to determine if all features within the FeatureList must // have the same size. The same holds for this FeatureList across multiple // examples. // // Examples of conformant and non-conformant examples' FeatureLists: // // Conformant FeatureLists: // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } } // } } // // Non-conformant FeatureLists (mismatched types): // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { int64_list: { value: [ 5 ] } } } // } } // // 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 ] } } } // } } // // Conformant pair of SequenceExample // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } } // } } // and: // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } // feature: { float_list: { value: [ 2.0 ] } } } // } } // // Conformant pair of SequenceExample // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } } // } } // and: // feature_lists: { feature_list: { // key: "movie_ratings" // value: { } // } } // // Conditionally conformant pair of SequenceExample, the parser configuration // determines if the second feature_lists is consistent (zero-length) or // invalid (missing "movie_ratings"): // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } } // } } // and: // feature_lists: { } // // Non-conformant pair of SequenceExample (mismatched types) // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.5 ] } } // feature: { float_list: { value: [ 5.0 ] } } } // } } // and: // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { int64_list: { value: [ 4 ] } } // feature: { int64_list: { value: [ 5 ] } } // feature: { int64_list: { value: [ 2 ] } } } // } } // // Conditionally conformant pair of SequenceExample; 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 ] } } } // } } // and: // feature_lists: { feature_list: { // key: "movie_ratings" // value: { feature: { float_list: { value: [ 4.0 ] } } // feature: { float_list: { value: [ 5.0, 3.0 ] } } // } } message SequenceExample { Features context = 1; FeatureLists feature_lists = 2; };
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号