Skip to content

Commit

Permalink
Additional dataset checker for moderation section was added!
Browse files Browse the repository at this point in the history
  • Loading branch information
ApelSYN committed Sep 13, 2024
1 parent 257f9a8 commit 6eb6e7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion moderation/app/controllers/moderation/storeKeypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function(ctx, next) {
//zone = require(anb_json)
zone = JSON.parse(fs.readFileSync(anb_json))
;
let add_params = ''

console.log("Request body:");
console.log(JSON.stringify(ctx.request.body));
Expand All @@ -51,6 +52,7 @@ module.exports = async function(ctx, next) {
cnt++;
if (cnt == 3) break;
}
add_params = ' -update_lines'
console.log(`Update lines from ${JSON.stringify(lines)}`);
zone.regions[ctx.request.body.key].lines = lines
}
Expand All @@ -59,7 +61,7 @@ module.exports = async function(ctx, next) {
console.log("Checkpoint 3 done");

// Rebuild lines
let cmd = `cd bin; ./rebuild_nn_dataset_image.py -anb_key ${ctx.request.body.basename} -dataset_dir ${base_dir} -rotate ${rotate} -debug`
let cmd = `cd bin; ./rebuild_nn_dataset_image.py -anb_key ${ctx.request.body.basename} -dataset_dir ${base_dir} -rotate ${rotate} -debug${add_params}`
console.log(`${cmd}`)
const { stdout, stderr } = await exec(cmd)
// rebuild_nn_dataset_image.py -anb_key p14955810 -dataset_dir /mnt/sdd1/datasets/2-3lines-test
Expand Down
5 changes: 4 additions & 1 deletion moderation/bin/rebuild_nn_dataset_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
help='Anb key for loadin image settings from anb/<anb_key>.json')
parser.add_argument('-dataset_dir', dest="dataset_dir", required=True, help='Path to datset files')
parser.add_argument('-rotate', dest="rotate", required=False, help='Rotate param', default=0, type=int)
parser.add_argument('-update_lines', dest="update_lines", required=False, help='Check update lines', default=False,
action=argparse.BooleanOptionalAction)
parser.add_argument('-debug', dest="debug", required=False, help='Debug mode', default=False,
action=argparse.BooleanOptionalAction)
args = parser.parse_args()

dataset_dir = args.dataset_dir
rotate = args.rotate
update_lines = args.update_lines
debug = args.debug
dataset_config = DatasetConfig(dataset_dir)
anb_key = args.anb_key
dataset_item = DatasetItem(dataset_config, anb_key, rotate, debug)
dataset_item = DatasetItem(dataset_config, anb_key, rotate, update_lines, debug)
# dataset_item = DatasetItem(dataset_config, anb_key)
dataset_item.recheck_regions()

27 changes: 25 additions & 2 deletions nomeroff_net/tools/nn_numberplate_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def __init__(self,
region_key: str,
region_data: List,
rotate: int = 0,
update_lines: bool = False,
debug: bool = False):
self.dataset_config = dataset_config
self.anb_key = anb_key
self.rotate = rotate
self.img = img
self.region_key = region_key
self.region_data = region_data
self.update_lines = update_lines
self.debug = debug

# normalize_keypoints
Expand Down Expand Up @@ -171,12 +173,31 @@ def rebuild_bbox(self):
self.write_ann_line_json(parts[idx], ann_basename_new, line, self.region_data["region_id"])
if os.path.isfile(img_path):
if self.debug:
print(f'Remove old image for line {1} "{img_path}"')
print(f'Remove old image for line {i} "{img_path}"')
os.remove(img_path)
if self.debug:
print(f'Create new line {i} image {img_path_new}')
cv2.imwrite(img_path_new, parts[idx])
idx += 1
if self.update_lines:
if self.debug:
print(f'CleanUp old lines')
cnt = len(self.region_data["lines"])
if cnt < 3:
for i in range(cnt, 3):
ann_basename = f'{self.region_key}-line-{i}'
ann_filename = f'{ann_basename}.{self.dataset_config.json_ext}'
img_filename = f'{ann_basename}.{self.dataset_config.img_ext}'
ann_path = os.path.join(self.dataset_config.ann_dir, ann_filename)
img_path = os.path.join(self.dataset_config.img_dir, img_filename)
if os.path.isfile(img_path):
if self.debug:
print(f'Remove old image for line {i} "{img_path}"')
os.remove(img_path)
if os.path.isfile(ann_path):
if self.debug:
print(f'Remove old annotation for line {i} "{ann_path}"')
os.remove(ann_path)

# p17667717-519x476-566x504

Expand Down Expand Up @@ -242,11 +263,13 @@ def __init__(self,
dataset_config: DatasetConfig,
anb_key: str,
rotate = 0,
debug: bool = False
update_lines: bool = False,
debug: bool = False,
):
self.version = 2
self.version = 2
self.rotate = rotate
self.update_lines = update_lines
self.debug = debug
self.dataset_config = dataset_config
self.anb_key = anb_key
Expand Down

0 comments on commit 6eb6e7f

Please sign in to comment.