• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2017, Apple Inc. All rights reserved.
2//
3// Use of this source code is governed by a BSD-3-clause license that can be
4// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
5
6syntax = "proto3";
7option optimize_for = LITE_RUNTIME;
8
9package CoreML.Specification;
10
11/**
12 * The 64-bit integer feature type.
13 */
14message Int64FeatureType {}
15
16/**
17 * The double-precision floating point number feature type.
18 */
19message DoubleFeatureType {}
20
21/**
22 * The string feature type.
23 */
24message StringFeatureType {}
25
26
27message SizeRange {
28    uint64 lowerBound = 1;
29    int64 upperBound = 2; // negative value means unbound otherwise upperbound is included in range
30}
31
32/**
33 * The image feature type.
34 */
35message ImageFeatureType {
36    // Assumes raw (decompressed) format
37    enum ColorSpace {
38        INVALID_COLOR_SPACE = 0;
39        GRAYSCALE = 10; //  8 bits per pixel
40        RGB = 20;       // 32 bits per pixel: RGBA with A channel ignored
41        BGR = 30;       // 32 bits per pixel: BGRA with A channel ignored
42    }
43
44    message ImageSize {
45        uint64 width = 1;
46        uint64 height = 2;
47    }
48
49    message EnumeratedImageSizes {
50        repeated ImageSize sizes = 1;
51    }
52
53    message ImageSizeRange {
54        SizeRange widthRange = 1;
55        SizeRange heightRange = 2;
56    }
57
58    // The required or default image size is width x height
59    //
60    // If specificationVersion <= 2 or SizeFlexibility is empty,
61    // width x height is the required fixed image size
62    //
63    // If SizeFlexibility is present, width x height indicate a "default"
64    // image size which must be consistent with the flexibilty specified
65
66    int64 width = 1;
67    int64 height = 2;
68
69    // For specification version >= 3 you can specify image size flexibility.
70
71    oneof SizeFlexibility {
72
73        // Use enumeratedSizes for a set of distinct fixed sizes
74        // e.g. portrait or landscape: [80 x 100, 100 x 8]
75        //
76        // If the width x height fields above are specified then they must be
77        // one of the sizes listed.
78        //
79        // If width and height are not specified above then the default width
80        // and height will be enumeratedSizes[0]
81        //
82        // Must be non-empty
83
84        EnumeratedImageSizes enumeratedSizes = 21;
85
86        // Use imageSizeRange to allow for ranges of values
87        // e.g. any image greater than 10 x 20: [10..<max] x [20..<max]
88        //
89        // If width and height are specified above they must fall in the range
90        // specified in imageSizeRange. They will be treated as the default size.
91        //
92        // If width and height are not specified above then the default width
93        // and height will be imageSizeRange.widthRange.lowerBound x imageSizeRange.heightRange.lowerBound
94
95        ImageSizeRange imageSizeRange = 31;
96    }
97
98    ColorSpace colorSpace = 3;
99}
100
101/**
102 * The array feature type.
103 */
104message ArrayFeatureType {
105
106    enum ArrayDataType {
107        INVALID_ARRAY_DATA_TYPE = 0;
108        FLOAT32 = 65568; // 0x10000 | 32
109        DOUBLE = 65600;  // 0x10000 | 64
110        INT32 = 131104;  // 0x20000 | 32
111    }
112
113    // The required or default shape
114    //
115    // If specificationVersion <= 2 or ShapeFlexibility is empty,
116    // shape is the required fixed shape
117    //
118    // If ShapeFlexibility is present, shape indicate a "default"
119    // shape which must be consistent with the flexibilty specified
120
121    repeated int64 shape = 1;
122
123    ArrayDataType dataType = 2;
124
125    message Shape {
126        repeated int64 shape = 1;
127    }
128
129    message EnumeratedShapes {
130        repeated Shape shapes = 1;
131    }
132
133    message ShapeRange {
134        // sizeRanges.size() must be length 1 or 3
135        // sizeRanges[d] specifies the allowed range for dimension d
136        repeated SizeRange sizeRanges = 1;
137    }
138
139    // For specification version >= 3 you can specify image size flexibility.
140
141    oneof ShapeFlexibility {
142
143        // Use enumeratedShapes for a set of distinct fixed shapes
144        //
145        // If the shape field is specified then it must be
146        // one of the enumerated shapes.
147        ///
148        // If shape is not specifed, the "default" shape will be considered
149        // enumeratedShapes[0]
150        //
151        // Must be non-empty
152
153        EnumeratedShapes enumeratedShapes = 21;
154
155        // Use shapeRange to allow the size of each dimension vary within
156        // indpendently specified ranges
157        //
158        // If you specify shape above it must fall in the range
159        // specified in shapeRanges. It will be treated as the default shape.
160        //
161        // If you don't specify shape above then the default shape will
162        // have shape[d] = shapeRange.sizeRanges[d].lowerBound
163
164        ShapeRange shapeRange = 31;
165
166    }
167
168    oneof defaultOptionalValue {
169        int32 intDefaultValue = 41;
170        float floatDefaultValue = 51;
171        double doubleDefaultValue = 61;
172    }
173
174}
175
176/**
177 * The dictionary feature type.
178 */
179message DictionaryFeatureType {
180    /**
181     *  Key/value type tags, with the following restrictions:
182     *  - ``keyType`` must be a hashable type
183     *  - ``valueType`` is assumed to be a ``double``
184     */
185    oneof KeyType {
186        Int64FeatureType int64KeyType = 1;
187        StringFeatureType stringKeyType = 2;
188    }
189}
190
191/**
192 * The Sequence feature type.
193 */
194message SequenceFeatureType {
195
196    /**
197     * Currently only categorical int64 and String sequences are supported
198     */
199    oneof Type {
200        Int64FeatureType int64Type = 1;
201        StringFeatureType stringType = 3;
202    }
203
204    // Range of allowed size/length/count of sequence
205    SizeRange sizeRange = 101;
206}
207
208/**
209 * A feature, which may be optional.
210 */
211message FeatureType {
212    oneof Type {
213        Int64FeatureType int64Type = 1;
214        DoubleFeatureType doubleType = 2;
215        StringFeatureType stringType = 3;
216        ImageFeatureType imageType = 4;
217        ArrayFeatureType multiArrayType = 5;
218        DictionaryFeatureType dictionaryType = 6;
219        SequenceFeatureType sequenceType = 7;
220    }
221
222    bool isOptional = 1000;
223}
224
225