def test_map_dict(self): def mapTest(val, key, *args): return val.upper() map = _.map({"foo": "bar", "bar": "foo"}, mapTest) self.assertEqual({"BAR", "FOO"}, set(map), "map for dicts did not work")
def test_map_list(self): def mapTest(val, *args): return val * 2 map = _.map([1, 2, 3, 4], mapTest) self.assertEqual([2, 4, 6, 8], map, "map for list did not work")
def cropImages(annots): return lambda images: _.go(_.zip(images, annots), _.map(cropImage), _. flatten)
def cropImage(r, *s): origin = parse(r[1]).getroot() boxes = origin.findall('object') return _.go(_.zip(boxes, [r[0] for i in range(len(boxes))]), _.map(_cropImage), _.flatten)
def writing(*x): _.map(x[0][1], lambda feature, *r: x[0][0].write(featureToSerialize(feature))) x[0][0].close()
images = sorted(glob('data/Images/*/*')) # labels = _.map(images, lambda x, *r: x.split('/')[2]) labels: dict = dict() # le.fit(labels) class_num = len(glob('data/Images/*')) annots = sorted(glob('data/Annotation/*/*')) # annots = _.take(annots, test_size) pp('Load data...') images = _.go( images, # _.take(test_size), # _.take(config.split), # _.shuffle, _.map(readFile), _.map(decodeJpeg), ) pp('Cropping all data...') croppedImages = _.go( images, cropImages(annots), saveLabels(labels), ) imageToFeature = _.pipe( # _.tap(pp), _.map(rgbToGrayscale), _.tap(pp),