Skip to content

Commit

Permalink
txt empty output
Browse files Browse the repository at this point in the history
  • Loading branch information
heabeounMKTO committed May 7, 2024
1 parent 9e1075a commit c598487
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/kesa_al.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
model::DatasetInfo,
output::OutputFormat,
};

use anyhow::{Error, Result};
use backends::compute_backends::{get_backend, ComputeBackendType, ModelVersion};
#[cfg(feature = "onnxruntime")]
Expand All @@ -32,7 +33,6 @@ use lazy_static::lazy_static;
use ndarray::{s, ArrayBase, Axis, Dim, IxDynImpl, OwnedRepr};
use plotting::draw_dummy_graph;
use rayon::prelude::*;
use spinners::{Spinner, Spinners};
use splash::print_splash;
use std::fs::{self, File};
use std::io::BufReader;
Expand Down
12 changes: 9 additions & 3 deletions src/kesa_aug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ fn main() -> Result<(), Error> {
let do_aug = get_random_aug().unwrap();

// FUCK THEM <<RESULT>> HANDLING KIDS
create_augmentation(do_aug, &file, &classes_hash, &export_format, &args.folder)
.unwrap();
let _c = create_augmentation(do_aug, &file, &classes_hash, &export_format, &args.folder);
match _c {
Ok(_) => {
},
Err(e) => {
eprintln!("error: {:?}", e);
}
};
}
});
prog.finish_with_message("[info]::kesa_aug: created augmentations!\n");
Expand Down Expand Up @@ -179,4 +185,4 @@ fn get_random_aug() -> Result<AugmentationType, Error> {
_ => panic!("[error]::kesa_aug: unknown augmentation type!"),
};
Ok(do_aug)
}
}
27 changes: 21 additions & 6 deletions src/kesa_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mod output;
mod splash;

use anyhow::{bail, Error, Result};
use clap::Parser;
use clap::{Parser, ArgAction};
use fileutils::{get_all_classes, open_image, ExportFolderOptions, get_json_from_image,get_all_images, write_labelme_to_json};
use image::{DynamicImage, GenericImageView};
use indicatif::ProgressBar;
use kesa::image_utils::dynimg2string;
use label::{read_labels_from_file,Shape, LabelmeAnnotation};
use label::{read_labels_from_file,Shape, LabelmeAnnotation, YoloAnnotation};
use rand::distributions::{Distribution, Uniform};
use rayon::prelude::*;
use spinoff::{spinners, Color, Spinner};
Expand All @@ -20,15 +20,17 @@ use std::collections::HashMap;
use std::fs::Metadata;
use std::{fs, path::PathBuf};

use crate::fileutils::{get_all_classes_hash, get_all_jsons, write_data_yaml, write_yolo_to_txt};

#[derive(Parser, Debug)]
struct CliArguments {
#[arg(long)]
folder: String,

#[arg(long)]
workers: Option<i64>
workers: Option<i64>,

#[arg(long, action=ArgAction::SetTrue)]
txt: bool
}

fn main() -> Result<(), Error> {
Expand All @@ -38,7 +40,7 @@ fn main() -> Result<(), Error> {
Some(_) => args.workers,
None => Some(4)
};

let write_txt = args.txt;
rayon::ThreadPoolBuilder::new()
.num_threads(workers.unwrap().try_into().unwrap())
.build_global()
Expand All @@ -56,13 +58,22 @@ fn main() -> Result<(), Error> {
all_images.par_iter_mut().for_each(|img| {
prog.inc(1);
let _json_path = get_json_from_image(&img).expect("[info]::kesa_fill: cannot convert to json path");
let mut _txt = img.to_owned();
_txt.set_extension("txt");
match std::fs::metadata(&_json_path) {
Ok(_) => {},
Err(_) => {
let _f = create_empty_annotation_from_image(&img);
match _f {
Ok(label) => {
write_labelme_to_json(&label,&img);
match write_txt {
false => {
write_labelme_to_json(&label,&img);
},
true => {
let _empty_txt_output = fs::File::create(_txt).unwrap();
}
}
},
Err(e) => {
eprintln!("[error]::kesa_fill: {:?}\ncannot create labelme json for file {:?}",e, &img);
Expand Down Expand Up @@ -94,3 +105,7 @@ fn create_empty_annotation_from_image(input_img: &PathBuf) -> Result<LabelmeAnno
)
)
}

fn create_empty_yolo_txt(input_img: &PathBuf) -> Result<(), Error> {
todo!()
}

0 comments on commit c598487

Please sign in to comment.