|
@@ -18,11 +18,17 @@ def main():
|
|
parser = argparse.ArgumentParser(
|
|
parser = argparse.ArgumentParser(
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
|
)
|
|
)
|
|
- parser.add_argument("input_dir", help="input annotated directory")
|
|
|
|
- parser.add_argument("output_dir", help="output dataset directory")
|
|
|
|
- parser.add_argument("--labels", help="labels file", required=True)
|
|
|
|
|
|
+ parser.add_argument("input_dir", help="Input annotated directory")
|
|
|
|
+ parser.add_argument("output_dir", help="Output dataset directory")
|
|
|
|
+ parser.add_argument("--labels", help="Labels file", required=True)
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
- "--noviz", help="no visualization", action="store_true"
|
|
|
|
|
|
+ "--noobject", help="Flag not to generate object label", action="store_true"
|
|
|
|
+ )
|
|
|
|
+ parser.add_argument(
|
|
|
|
+ "--nonpy", help="Flag not to generate .npy files", action="store_true"
|
|
|
|
+ )
|
|
|
|
+ parser.add_argument(
|
|
|
|
+ "--noviz", help="Flag to disable visualization", action="store_true"
|
|
)
|
|
)
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
@@ -32,17 +38,16 @@ def main():
|
|
os.makedirs(args.output_dir)
|
|
os.makedirs(args.output_dir)
|
|
os.makedirs(osp.join(args.output_dir, "JPEGImages"))
|
|
os.makedirs(osp.join(args.output_dir, "JPEGImages"))
|
|
os.makedirs(osp.join(args.output_dir, "SegmentationClass"))
|
|
os.makedirs(osp.join(args.output_dir, "SegmentationClass"))
|
|
- os.makedirs(osp.join(args.output_dir, "SegmentationClassPNG"))
|
|
|
|
- if not args.noviz:
|
|
|
|
- os.makedirs(
|
|
|
|
- osp.join(args.output_dir, "SegmentationClassVisualization")
|
|
|
|
- )
|
|
|
|
- os.makedirs(osp.join(args.output_dir, "SegmentationObject"))
|
|
|
|
- os.makedirs(osp.join(args.output_dir, "SegmentationObjectPNG"))
|
|
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ os.makedirs(osp.join(args.output_dir, "SegmentationClassNpy"))
|
|
if not args.noviz:
|
|
if not args.noviz:
|
|
- os.makedirs(
|
|
|
|
- osp.join(args.output_dir, "SegmentationObjectVisualization")
|
|
|
|
- )
|
|
|
|
|
|
+ os.makedirs(osp.join(args.output_dir, "SegmentationClassVisualization"))
|
|
|
|
+ if not args.noobject:
|
|
|
|
+ os.makedirs(osp.join(args.output_dir, "SegmentationObject"))
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ os.makedirs(osp.join(args.output_dir, "SegmentationObjectNpy"))
|
|
|
|
+ if not args.noviz:
|
|
|
|
+ os.makedirs(osp.join(args.output_dir, "SegmentationObjectVisualization"))
|
|
print("Creating dataset:", args.output_dir)
|
|
print("Creating dataset:", args.output_dir)
|
|
|
|
|
|
class_names = []
|
|
class_names = []
|
|
@@ -71,30 +76,31 @@ def main():
|
|
|
|
|
|
base = osp.splitext(osp.basename(filename))[0]
|
|
base = osp.splitext(osp.basename(filename))[0]
|
|
out_img_file = osp.join(args.output_dir, "JPEGImages", base + ".jpg")
|
|
out_img_file = osp.join(args.output_dir, "JPEGImages", base + ".jpg")
|
|
- out_cls_file = osp.join(
|
|
|
|
- args.output_dir, "SegmentationClass", base + ".npy"
|
|
|
|
- )
|
|
|
|
- out_clsp_file = osp.join(
|
|
|
|
- args.output_dir, "SegmentationClassPNG", base + ".png"
|
|
|
|
- )
|
|
|
|
|
|
+ out_clsp_file = osp.join(args.output_dir, "SegmentationClass", base + ".png")
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ out_cls_file = osp.join(
|
|
|
|
+ args.output_dir, "SegmentationClassNpy", base + ".npy"
|
|
|
|
+ )
|
|
if not args.noviz:
|
|
if not args.noviz:
|
|
out_clsv_file = osp.join(
|
|
out_clsv_file = osp.join(
|
|
args.output_dir,
|
|
args.output_dir,
|
|
"SegmentationClassVisualization",
|
|
"SegmentationClassVisualization",
|
|
base + ".jpg",
|
|
base + ".jpg",
|
|
)
|
|
)
|
|
- out_ins_file = osp.join(
|
|
|
|
- args.output_dir, "SegmentationObject", base + ".npy"
|
|
|
|
- )
|
|
|
|
- out_insp_file = osp.join(
|
|
|
|
- args.output_dir, "SegmentationObjectPNG", base + ".png"
|
|
|
|
- )
|
|
|
|
- if not args.noviz:
|
|
|
|
- out_insv_file = osp.join(
|
|
|
|
- args.output_dir,
|
|
|
|
- "SegmentationObjectVisualization",
|
|
|
|
- base + ".jpg",
|
|
|
|
|
|
+ if not args.noobject:
|
|
|
|
+ out_insp_file = osp.join(
|
|
|
|
+ args.output_dir, "SegmentationObject", base + ".png"
|
|
)
|
|
)
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ out_ins_file = osp.join(
|
|
|
|
+ args.output_dir, "SegmentationObjectNpy", base + ".npy"
|
|
|
|
+ )
|
|
|
|
+ if not args.noviz:
|
|
|
|
+ out_insv_file = osp.join(
|
|
|
|
+ args.output_dir,
|
|
|
|
+ "SegmentationObjectVisualization",
|
|
|
|
+ base + ".jpg",
|
|
|
|
+ )
|
|
|
|
|
|
img = labelme.utils.img_data_to_arr(label_file.imageData)
|
|
img = labelme.utils.img_data_to_arr(label_file.imageData)
|
|
imgviz.io.imsave(out_img_file, img)
|
|
imgviz.io.imsave(out_img_file, img)
|
|
@@ -108,7 +114,8 @@ def main():
|
|
|
|
|
|
# class label
|
|
# class label
|
|
labelme.utils.lblsave(out_clsp_file, cls)
|
|
labelme.utils.lblsave(out_clsp_file, cls)
|
|
- np.save(out_cls_file, cls)
|
|
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ np.save(out_cls_file, cls)
|
|
if not args.noviz:
|
|
if not args.noviz:
|
|
clsv = imgviz.label2rgb(
|
|
clsv = imgviz.label2rgb(
|
|
cls,
|
|
cls,
|
|
@@ -119,20 +126,22 @@ def main():
|
|
)
|
|
)
|
|
imgviz.io.imsave(out_clsv_file, clsv)
|
|
imgviz.io.imsave(out_clsv_file, clsv)
|
|
|
|
|
|
- # instance label
|
|
|
|
- labelme.utils.lblsave(out_insp_file, ins)
|
|
|
|
- np.save(out_ins_file, ins)
|
|
|
|
- if not args.noviz:
|
|
|
|
- instance_ids = np.unique(ins)
|
|
|
|
- instance_names = [str(i) for i in range(max(instance_ids) + 1)]
|
|
|
|
- insv = imgviz.label2rgb(
|
|
|
|
- ins,
|
|
|
|
- imgviz.rgb2gray(img),
|
|
|
|
- label_names=instance_names,
|
|
|
|
- font_size=15,
|
|
|
|
- loc="rb",
|
|
|
|
- )
|
|
|
|
- imgviz.io.imsave(out_insv_file, insv)
|
|
|
|
|
|
+ if not args.noobject:
|
|
|
|
+ # instance label
|
|
|
|
+ labelme.utils.lblsave(out_insp_file, ins)
|
|
|
|
+ if not args.nonpy:
|
|
|
|
+ np.save(out_ins_file, ins)
|
|
|
|
+ if not args.noviz:
|
|
|
|
+ instance_ids = np.unique(ins)
|
|
|
|
+ instance_names = [str(i) for i in range(max(instance_ids) + 1)]
|
|
|
|
+ insv = imgviz.label2rgb(
|
|
|
|
+ ins,
|
|
|
|
+ imgviz.rgb2gray(img),
|
|
|
|
+ label_names=instance_names,
|
|
|
|
+ font_size=15,
|
|
|
|
+ loc="rb",
|
|
|
|
+ )
|
|
|
|
+ imgviz.io.imsave(out_insv_file, insv)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|