From 514331c52a5a00b98506223d4b085d586f703022 Mon Sep 17 00:00:00 2001 From: Bobholamovic Date: Thu, 8 Sep 2022 22:04:10 +0800 Subject: [PATCH] Fix tools import bugs --- tools/coco2mask.py | 14 +++++++------- tools/mask2geojson.py | 18 ++++++++++-------- tools/mask2shape.py | 20 ++++++++++---------- tools/match.py | 24 ++++++++++++------------ tools/oif.py | 14 +++++++------- tools/pca.py | 16 ++++++++-------- tools/split.py | 21 +++++++++++---------- 7 files changed, 65 insertions(+), 62 deletions(-) diff --git a/tools/coco2mask.py b/tools/coco2mask.py index b6d4e6c..b71e54f 100644 --- a/tools/coco2mask.py +++ b/tools/coco2mask.py @@ -19,8 +19,9 @@ import json import argparse from collections import defaultdict -import cv2 +import paddlers import numpy as np +import cv2 import glob from tqdm import tqdm from PIL import Image @@ -101,12 +102,11 @@ def convert_data(raw_dir, end_dir): lab_save_path) -parser = argparse.ArgumentParser() -parser.add_argument("--raw_dir", type=str, required=True, \ - help="Directory that contains original data, where `images` stores the original image and `annotation.json` stores the corresponding annotation information.") -parser.add_argument("--save_dir", type=str, required=True, \ - help="Directory to save the results, where `img` stores the image and `gt` stores the label.") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--raw_dir", type=str, required=True, \ + help="Directory that contains original data, where `images` stores the original image and `annotation.json` stores the corresponding annotation information.") + parser.add_argument("--save_dir", type=str, required=True, \ + help="Directory to save the results, where `img` stores the image and `gt` stores the label.") args = parser.parse_args() convert_data(args.raw_dir, args.save_dir) diff --git a/tools/mask2geojson.py b/tools/mask2geojson.py index 0b213d4..e9d45cd 100644 --- a/tools/mask2geojson.py +++ b/tools/mask2geojson.py @@ -14,11 +14,14 @@ import os import codecs -import cv2 -import numpy as np import argparse + +import paddlers +import numpy as np +import cv2 import geojson from tqdm import tqdm + from utils import Raster, save_geotiff, translate_vector, time_it @@ -60,12 +63,11 @@ def convert_data(image_path, geojson_path): os.remove(temp_geojson_path) -parser = argparse.ArgumentParser() -parser.add_argument("--mask_path", type=str, required=True, \ - help="Path of mask data.") -parser.add_argument("--save_path", type=str, required=True, \ - help="Path to store the GeoJSON file (the coordinate system is WGS84).") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--mask_path", type=str, required=True, \ + help="Path of mask data.") + parser.add_argument("--save_path", type=str, required=True, \ + help="Path to store the GeoJSON file (the coordinate system is WGS84).") args = parser.parse_args() convert_data(args.raster_path, args.geojson_path) diff --git a/tools/mask2shape.py b/tools/mask2shape.py index 4f108ba..855a69c 100644 --- a/tools/mask2shape.py +++ b/tools/mask2shape.py @@ -16,6 +16,7 @@ import os import os.path as osp import argparse +import paddlers import numpy as np from PIL import Image try: @@ -89,17 +90,16 @@ def mask2shape(srcimg_path, mask_path, save_path, ignore_index=255): vec_ext) -parser = argparse.ArgumentParser() -parser.add_argument("--mask_path", type=str, required=True, \ - help="Path of mask data.") -parser.add_argument("--save_path", type=str, required=True, \ - help="Path to save the shape file (the extension is .json/geojson or .shp).") -parser.add_argument("--srcimg_path", type=str, default="", \ - help="Path of original data with geoinfo. Default to empty.") -parser.add_argument("--ignore_index", type=int, default=255, \ - help="The ignored index will not be converted to a value in the shape file. Default value is 255.") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--mask_path", type=str, required=True, \ + help="Path of mask data.") + parser.add_argument("--save_path", type=str, required=True, \ + help="Path to save the shape file (the extension is .json/geojson or .shp).") + parser.add_argument("--srcimg_path", type=str, default="", \ + help="Path of original data with geoinfo. Default to empty.") + parser.add_argument("--ignore_index", type=int, default=255, \ + help="The ignored index will not be converted to a value in the shape file. Default value is 255.") args = parser.parse_args() mask2shape(args.srcimg_path, args.mask_path, args.save_path, args.ignore_index) diff --git a/tools/match.py b/tools/match.py index fbcd991..9aa5cee 100644 --- a/tools/match.py +++ b/tools/match.py @@ -14,6 +14,7 @@ import argparse +import paddlers import numpy as np import cv2 @@ -78,19 +79,18 @@ def match(im1_path, im1_ras.datatype) -parser = argparse.ArgumentParser(description="input parameters") -parser.add_argument('--im1_path', type=str, required=True, \ - help="Path of time1 image (with geoinfo).") -parser.add_argument('--im2_path', type=str, required=True, \ - help="Path of time2 image.") -parser.add_argument('--save_path', type=str, required=True, \ - help="Path to save matching result.") -parser.add_argument('--im1_bands', type=int, nargs="+", default=[1, 2, 3], \ - help="Bands of im1 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].") -parser.add_argument('--im2_bands', type=int, nargs="+", default=[1, 2, 3], \ - help="Bands of im2 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].") - if __name__ == "__main__": + parser = argparse.ArgumentParser(description="input parameters") + parser.add_argument('--im1_path', type=str, required=True, \ + help="Path of time1 image (with geoinfo).") + parser.add_argument('--im2_path', type=str, required=True, \ + help="Path of time2 image.") + parser.add_argument('--save_path', type=str, required=True, \ + help="Path to save matching result.") + parser.add_argument('--im1_bands', type=int, nargs="+", default=[1, 2, 3], \ + help="Bands of im1 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].") + parser.add_argument('--im2_bands', type=int, nargs="+", default=[1, 2, 3], \ + help="Bands of im2 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].") args = parser.parse_args() match(args.im1_path, args.im2_path, args.save_path, args.im1_bands, args.im2_bands) diff --git a/tools/oif.py b/tools/oif.py index ab01386..08b5475 100644 --- a/tools/oif.py +++ b/tools/oif.py @@ -14,10 +14,11 @@ import itertools import argparse -from easydict import EasyDict as edict +import paddlers import numpy as np import pandas as pd +from easydict import EasyDict as edict from utils import Raster, time_it @@ -55,12 +56,11 @@ def oif(img_path, topk=5): print("Bands: {0}, OIF value: {1}.".format(k, v)) -parser = argparse.ArgumentParser() -parser.add_argument("--im_path", type=str, required=True, \ - help="Path of HSIs image.") -parser.add_argument("--topk", type=int, default=5, \ - help="Number of top results. The default value is 5.") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--im_path", type=str, required=True, \ + help="Path of HSIs image.") + parser.add_argument("--topk", type=int, default=5, \ + help="Number of top results. The default value is 5.") args = parser.parse_args() oif(args.im_path, args.topk) diff --git a/tools/pca.py b/tools/pca.py index e025529..7ef2f19 100644 --- a/tools/pca.py +++ b/tools/pca.py @@ -17,6 +17,7 @@ import os.path as osp import numpy as np import argparse +import paddlers from sklearn.decomposition import PCA from joblib import dump @@ -43,14 +44,13 @@ def pca_train(img_path, save_dir="output", dim=3): save_dir)) -parser = argparse.ArgumentParser() -parser.add_argument("--im_path", type=str, required=True, \ - help="Path of HSIs image.") -parser.add_argument("--save_dir", type=str, default="output", \ - help="Directory to save PCA params(*.joblib). Default: output.") -parser.add_argument("--dim", type=int, default=3, \ - help="Dimension to reduce to. Default: 3.") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--im_path", type=str, required=True, \ + help="Path of HSIs image.") + parser.add_argument("--save_dir", type=str, default="output", \ + help="Directory to save PCA params(*.joblib). Default: output.") + parser.add_argument("--dim", type=int, default=3, \ + help="Dimension to reduce to. Default: 3.") args = parser.parse_args() pca_train(args.im_path, args.save_dir, args.dim) diff --git a/tools/split.py b/tools/split.py index 8d6ce31..6c29ac0 100644 --- a/tools/split.py +++ b/tools/split.py @@ -16,6 +16,8 @@ import os import os.path as osp import argparse from math import ceil + +import paddlers from tqdm import tqdm from utils import Raster, save_geotiff, time_it @@ -67,16 +69,15 @@ def split_data(image_path, mask_path, block_size, save_dir): pbar.update(1) -parser = argparse.ArgumentParser(description="input parameters") -parser.add_argument("--image_path", type=str, required=True, \ - help="Path of input image.") -parser.add_argument("--mask_path", type=str, default=None, \ - help="Path of input labels.") -parser.add_argument("--block_size", type=int, default=512, \ - help="Size of image block. Default value is 512.") -parser.add_argument("--save_dir", type=str, default="dataset", \ - help="Directory to save the results. Default value is 'dataset'.") - if __name__ == "__main__": + parser = argparse.ArgumentParser(description="input parameters") + parser.add_argument("--image_path", type=str, required=True, \ + help="Path of input image.") + parser.add_argument("--mask_path", type=str, default=None, \ + help="Path of input labels.") + parser.add_argument("--block_size", type=int, default=512, \ + help="Size of image block. Default value is 512.") + parser.add_argument("--save_dir", type=str, default="dataset", \ + help="Directory to save the results. Default value is 'dataset'.") args = parser.parse_args() split_data(args.image_path, args.mask_path, args.block_size, args.save_dir)