1
1
package vision
2
2
3
3
import (
4
- "bytes"
5
4
context "context"
5
+ "fmt"
6
6
"path"
7
7
"path/filepath"
8
8
"strings"
9
9
10
+ "github.com/rai-project/dldataset/vision/support/object_detection"
11
+
10
12
"github.com/Unknwon/com"
11
13
"github.com/pkg/errors"
12
14
"github.com/rai-project/config"
@@ -16,7 +18,6 @@ import (
16
18
"github.com/rai-project/dlframework"
17
19
"github.com/rai-project/dlframework/framework/feature"
18
20
"github.com/rai-project/downloadmanager"
19
- "github.com/rai-project/image"
20
21
"github.com/rai-project/image/types"
21
22
protobuf "github.com/ubccr/terf/protobuf"
22
23
)
@@ -37,11 +38,13 @@ type CocoLabeledImage struct {
37
38
// CocoValidationTFRecord ...
38
39
type CocoValidationTFRecord struct {
39
40
base
40
- name string
41
- baseURL string
42
- recordFileName string
43
- md5sum string
44
- recordReader * reader.TFRecordReader
41
+ name string
42
+ baseURL string
43
+ recordFileName string
44
+ md5sum string
45
+ labelMap object_detection.StringIntLabelMap
46
+ completeLabelMap object_detection.StringIntLabelMap
47
+ recordReader * reader.TFRecordReader
45
48
}
46
49
47
50
var (
@@ -157,24 +160,10 @@ func (d *CocoValidationTFRecord) Next(ctx context.Context) (dldataset.LabeledDat
157
160
return nil , err
158
161
}
159
162
160
- return nextCocoFromRecord (rec ), nil
163
+ return NewCocoLabeledImageFromRecord (rec ), nil
161
164
}
162
165
163
- func getImageRecord (data []byte , format string ) (* types.RGBImage , error ) {
164
- img , err := image .Read (bytes .NewBuffer (data ), image .Context (nil ))
165
- if err != nil {
166
- return nil , err
167
- }
168
-
169
- rgbImage , ok := img .(* types.RGBImage )
170
- if ! ok {
171
- return nil , errors .Errorf ("expecting an rgb image" )
172
- }
173
-
174
- return rgbImage , nil
175
- }
176
-
177
- func nextCocoFromRecord (rec * protobuf.Example ) * CocoLabeledImage {
166
+ func NewCocoLabeledImageFromRecord (rec * protobuf.Example ) * CocoLabeledImage {
178
167
height := tfrecord .FeatureInt64 (rec , "image/height" )
179
168
width := tfrecord .FeatureInt64 (rec , "image/width" )
180
169
fileName := tfrecord .FeatureString (rec , "image/filename" )
@@ -203,6 +192,8 @@ func nextCocoFromRecord(rec *protobuf.Example) *CocoLabeledImage {
203
192
feature .BoundingBoxYmin (bboxYmin [ii ]),
204
193
feature .BoundingBoxYmax (bboxYmax [ii ]),
205
194
feature .BoundingBoxLabel (class [ii ]),
195
+ feature .AppendMetadata ("isCrowd" , isCrowd [ii ]),
196
+ feature .AppendMetadata ("area" , area [ii ]),
206
197
)
207
198
}
208
199
@@ -224,27 +215,41 @@ func init() {
224
215
225
216
const baseURLPrefix = "https://s3.amazonaws.com/store.carml.org/datasets"
226
217
218
+ labelMap , err := object_detection .Get ("mscoco_label_map.pbtxt" )
219
+ if err != nil {
220
+ panic (fmt .Sprintf ("failed to get mscoco_label_map.pbtxt due to %v" , err ))
221
+ }
222
+
223
+ completeLabelMap , err := object_detection .Get ("mscoco_complete_label_map.pbtxt" )
224
+ if err != nil {
225
+ panic (fmt .Sprintf ("failed to get mscoco_complete_label_map.pbtxt due to %v" , err ))
226
+ }
227
+
227
228
baseWorkingDir := filepath .Join (dldataset .Config .WorkingDirectory , "dldataset" )
228
229
coco2014ValidationTFRecord = & CocoValidationTFRecord {
229
230
base : base {
230
231
ctx : context .Background (),
231
232
baseWorkingDir : baseWorkingDir ,
232
233
},
233
- name : "coco2014" ,
234
- baseURL : baseURLPrefix + "/coco2014" ,
235
- recordFileName : "coco_val.record-00000-of-00001" ,
236
- md5sum : "b1f63512f72d3c84792a1f53ec40062a" ,
234
+ name : "coco2014" ,
235
+ baseURL : baseURLPrefix + "/coco2014" ,
236
+ labelMap : labelMap ,
237
+ completeLabelMap : completeLabelMap ,
238
+ recordFileName : "coco_val.record-00000-of-00001" ,
239
+ md5sum : "b1f63512f72d3c84792a1f53ec40062a" ,
237
240
}
238
241
239
242
coco2017ValidationTFRecord = & CocoValidationTFRecord {
240
243
base : base {
241
244
ctx : context .Background (),
242
245
baseWorkingDir : baseWorkingDir ,
243
246
},
244
- name : "coco2017" ,
245
- baseURL : baseURLPrefix + "/coco2017" ,
246
- recordFileName : "coco_val.record-00000-of-00001" ,
247
- md5sum : "b8a0cfed5ad569d4572b4ad8645acb5b" ,
247
+ name : "coco2017" ,
248
+ baseURL : baseURLPrefix + "/coco2017" ,
249
+ labelMap : labelMap ,
250
+ completeLabelMap : completeLabelMap ,
251
+ recordFileName : "coco_val.record-00000-of-00001" ,
252
+ md5sum : "b8a0cfed5ad569d4572b4ad8645acb5b" ,
248
253
}
249
254
250
255
dldataset .Register (coco2014ValidationTFRecord )
0 commit comments