Skip to content

Commit b3b48fd

Browse files
author
abdul dakkak
authored
Merge pull request #3 from rai-project/feature/dataset/vision/pascal
Feature/dataset/vision/pascal
2 parents 3153759 + 4330e1d commit b3b48fd

29 files changed

+33140
-49
lines changed

Gopkg.lock

+160-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@
8888
[prune]
8989
go-tests = true
9090
unused-packages = true
91+
92+
[[constraint]]
93+
branch = "master"
94+
name = "github.com/ubccr/terf"

vision/coco.go

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package vision
22

33
import (
4-
"bytes"
54
context "context"
5+
"fmt"
66
"path"
77
"path/filepath"
88
"strings"
99

10+
"github.com/rai-project/dldataset/vision/support/object_detection"
11+
1012
"github.com/Unknwon/com"
1113
"github.com/pkg/errors"
1214
"github.com/rai-project/config"
@@ -16,7 +18,6 @@ import (
1618
"github.com/rai-project/dlframework"
1719
"github.com/rai-project/dlframework/framework/feature"
1820
"github.com/rai-project/downloadmanager"
19-
"github.com/rai-project/image"
2021
"github.com/rai-project/image/types"
2122
protobuf "github.com/ubccr/terf/protobuf"
2223
)
@@ -37,11 +38,13 @@ type CocoLabeledImage struct {
3738
// CocoValidationTFRecord ...
3839
type CocoValidationTFRecord struct {
3940
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
4548
}
4649

4750
var (
@@ -157,24 +160,10 @@ func (d *CocoValidationTFRecord) Next(ctx context.Context) (dldataset.LabeledDat
157160
return nil, err
158161
}
159162

160-
return nextCocoFromRecord(rec), nil
163+
return NewCocoLabeledImageFromRecord(rec), nil
161164
}
162165

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 {
178167
height := tfrecord.FeatureInt64(rec, "image/height")
179168
width := tfrecord.FeatureInt64(rec, "image/width")
180169
fileName := tfrecord.FeatureString(rec, "image/filename")
@@ -203,6 +192,8 @@ func nextCocoFromRecord(rec *protobuf.Example) *CocoLabeledImage {
203192
feature.BoundingBoxYmin(bboxYmin[ii]),
204193
feature.BoundingBoxYmax(bboxYmax[ii]),
205194
feature.BoundingBoxLabel(class[ii]),
195+
feature.AppendMetadata("isCrowd", isCrowd[ii]),
196+
feature.AppendMetadata("area", area[ii]),
206197
)
207198
}
208199

@@ -224,27 +215,41 @@ func init() {
224215

225216
const baseURLPrefix = "https://s3.amazonaws.com/store.carml.org/datasets"
226217

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+
227228
baseWorkingDir := filepath.Join(dldataset.Config.WorkingDirectory, "dldataset")
228229
coco2014ValidationTFRecord = &CocoValidationTFRecord{
229230
base: base{
230231
ctx: context.Background(),
231232
baseWorkingDir: baseWorkingDir,
232233
},
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",
237240
}
238241

239242
coco2017ValidationTFRecord = &CocoValidationTFRecord{
240243
base: base{
241244
ctx: context.Background(),
242245
baseWorkingDir: baseWorkingDir,
243246
},
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",
248253
}
249254

250255
dldataset.Register(coco2014ValidationTFRecord)

0 commit comments

Comments
 (0)