diff --git a/src/common/augment.rs b/src/common/augment.rs index 0b7f9fc..fd41104 100644 --- a/src/common/augment.rs +++ b/src/common/augment.rs @@ -23,7 +23,7 @@ pub async fn split_images(dataset_path: &String, target_height: &u32, target_wid if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -33,7 +33,7 @@ pub async fn split_images(dataset_path: &String, target_height: &u32, target_wid .map(|x| x.unwrap().path()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } let mut threads = JoinSet::new(); @@ -118,7 +118,7 @@ pub async fn split_images(dataset_path: &String, target_height: &u32, target_wid ) .expect_or_log("Failed to crop image"); let path = format!( - "{}\\output\\{}_LTR_x{}_y{}.{}", + "{}/output/{}_LTR_x{}_y{}.{}", entry.parent().unwrap().to_str().unwrap(), file_stem, x_index, @@ -171,7 +171,7 @@ pub async fn split_images(dataset_path: &String, target_height: &u32, target_wid ) .expect_or_log("Failed to crop image"); let path = format!( - "{}\\output\\{}_RTL_x{}_y{}.{}", + "{}/output/{}_RTL_x{}_y{}.{}", entry.parent().unwrap().to_str().unwrap(), file_stem, x_index, @@ -219,7 +219,7 @@ pub async fn split_images_with_bias( let entries = fs::read_dir(dataset_path).unwrap(); let mut threads = JoinSet::new(); - fs::create_dir_all(format!("{}\\..\\output\\", dataset_path)).unwrap(); + fs::create_dir_all(format!("{}/../output/", dataset_path)).unwrap(); for entry in entries { let entry = entry.unwrap(); @@ -272,7 +272,7 @@ pub async fn split_images_with_bias( .unwrap(); imgcodecs::imwrite( format!( - "{}\\..\\output\\{}_LTR_bias{}_x{}_y{}.{}", + "{}/../output/{}_LTR_bias{}_x{}_y{}.{}", dataset_path, entry.path().file_stem().unwrap().to_str().unwrap(), bias, @@ -328,7 +328,7 @@ pub async fn split_images_with_bias( .unwrap(); imgcodecs::imwrite( format!( - "{}\\..\\output\\{}_RTL_bias{}_x{}_y{}.{}", + "{}/../output/{}_RTL_bias{}_x{}_y{}.{}", dataset_path, entry.path().file_stem().unwrap().to_str().unwrap(), bias, @@ -450,11 +450,11 @@ pub async fn filter_dataset_with_rgblist( .map(|e| e.unwrap().path()) .collect(); - image_output_path = format!("{}\\filtered_images\\", image_path.to_str().unwrap()); + image_output_path = format!("{}/filtered_images/", image_path.to_str().unwrap()); } else { image_entries = vec![image_path.clone()]; image_output_path = format!( - "{}\\filtered\\images\\", + "{}/filtered/images/", image_path.parent().unwrap().to_str().unwrap() ); } @@ -465,11 +465,11 @@ pub async fn filter_dataset_with_rgblist( .map(|e| e.unwrap().path()) .collect(); - label_output_path = format!("{}\\filtered_labels\\", label_path.to_str().unwrap()); + label_output_path = format!("{}/filtered_labels/", label_path.to_str().unwrap()); } else { label_entries = vec![label_path.clone()]; label_output_path = format!( - "{}\\filtered\\labels\\", + "{}/filtered/labels/", label_path.parent().unwrap().to_str().unwrap() ); } @@ -662,11 +662,11 @@ pub async fn split_images_with_filter( .map(|e| e.unwrap().path()) .collect(); - label_output_path = format!("{}\\output\\", label_path.to_str().unwrap()); + label_output_path = format!("{}/output/", label_path.to_str().unwrap()); } else { label_entries = vec![label_path.clone()]; label_output_path = format!( - "{}\\output\\labels\\", + "{}/output/labels/", label_path.parent().unwrap().to_str().unwrap() ); } @@ -749,7 +749,7 @@ pub async fn split_images_with_filter( if check_valid_pixel_count(&cropped, &rgb_list, valid_rgb_mode).0 { imgcodecs::imwrite( &format!( - "{}\\{}.{}", + "{}/{}.{}", label_output_path, label_id, label_extension.as_ref().unwrap() @@ -792,7 +792,7 @@ pub async fn split_images_with_filter( if check_valid_pixel_count(&cropped, &rgb_list, valid_rgb_mode).0 { imgcodecs::imwrite( &format!( - "{}\\{}.{}", + "{}/{}.{}", label_output_path, label_id, label_extension.as_ref().unwrap() @@ -906,7 +906,7 @@ pub async fn stich_images(splited_images: &String, target_height: &i32, target_w } imgcodecs::imwrite( - format!("{}\\stiched.png", splited_images).as_str(), + format!("{}/stiched.png", splited_images).as_str(), &result_mat, &core::Vector::new(), ) diff --git a/src/common/convert.rs b/src/common/convert.rs index feb6b44..3c72e7b 100644 --- a/src/common/convert.rs +++ b/src/common/convert.rs @@ -155,7 +155,7 @@ pub async fn rgb2rle(dataset_path: &String, rgb_list: &str) { let dataset_guard = dataset.lock().unwrap(); let dataset_string = serde_json::to_string(&*dataset_guard).unwrap(); fs::write( - format!("{}\\resized_labels.json", dataset_path), + format!("{}/resized_labels.json", dataset_path), dataset_string, ) .unwrap(); diff --git a/src/common/dataset.rs b/src/common/dataset.rs index 58191f7..78feb28 100644 --- a/src/common/dataset.rs +++ b/src/common/dataset.rs @@ -255,19 +255,19 @@ pub async fn generate_dataset_txt(dataset_path: &String, train_ratio: &f32) { let dataset_path = dataset_path.to_str().unwrap(); fs::write( - format!("{}\\..\\val.txt", dataset_path), + format!("{}/../val.txt", dataset_path), valid_data.concat(), ) .unwrap(); fs::write( - format!("{}\\..\\train.txt", dataset_path), + format!("{}/../train.txt", dataset_path), train_data.concat(), ) .unwrap(); tracing::info!("Train dataset length: {}", train_data.len()); - tracing::info!("Saved to {}\\..\\train.txt", dataset_path); + tracing::info!("Saved to {}/../train.txt", dataset_path); tracing::info!("Valid dataset length: {}", valid_data.len()); - tracing::info!("Saved to {}\\..\\val.txt", dataset_path); + tracing::info!("Saved to {}/../val.txt", dataset_path); tracing::info!("Dataset split done"); } diff --git a/src/common/operation.rs b/src/common/operation.rs index 7c6882e..726d04e 100644 --- a/src/common/operation.rs +++ b/src/common/operation.rs @@ -20,7 +20,7 @@ pub async fn resize_images( if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -30,7 +30,7 @@ pub async fn resize_images( .map(|x| x.unwrap().path()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } @@ -80,7 +80,7 @@ pub async fn resize_images( imwrite( format!( - "{}\\output\\{}", + "{}/output/{}", entry.parent().unwrap().to_str().unwrap(), entry.file_name().unwrap().to_str().unwrap() ) @@ -184,7 +184,7 @@ pub fn crop_rectangle_region(source_path: &String, target_path: &String, corners pub fn normalize(dataset_path: &String, target_max: &f64, target_min: &f64) { let entries = fs::read_dir(dataset_path).expect_or_log("Failed to read directory"); - fs::create_dir_all(format!("{}\\output\\", dataset_path)) + fs::create_dir_all(format!("{}/output/", dataset_path)) .expect_or_log("Failed to create directory"); for entry in entries { @@ -221,7 +221,7 @@ pub fn normalize(dataset_path: &String, target_max: &f64, target_min: &f64) { .expect_or_log("Failed to normalize"); let dst_path = format!( - "{}\\output\\{}", + "{}/output/{}", dataset_path, entry .path() diff --git a/src/common/remap.rs b/src/common/remap.rs index d8c6b29..d129510 100644 --- a/src/common/remap.rs +++ b/src/common/remap.rs @@ -40,7 +40,7 @@ pub async fn remap_color(original_color: &str, new_color: &str, dataset_path: &S if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -49,7 +49,7 @@ pub async fn remap_color(original_color: &str, new_color: &str, dataset_path: &S .unwrap() .map(|x| x.unwrap().path()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } @@ -108,7 +108,7 @@ pub async fn remap_color(original_color: &str, new_color: &str, dataset_path: &S imwrite( format!( - "{}\\output\\{}", + "{}/output/{}", entry.parent().unwrap().to_str().unwrap(), entry.file_name().unwrap().to_str().unwrap() ) @@ -162,7 +162,7 @@ pub async fn remap_background_color(valid_colors: &str, new_color: &str, dataset if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -171,7 +171,7 @@ pub async fn remap_background_color(valid_colors: &str, new_color: &str, dataset .unwrap() .map(|x| x.unwrap().path()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } @@ -228,7 +228,7 @@ pub async fn remap_background_color(valid_colors: &str, new_color: &str, dataset imwrite( format!( - "{}\\output\\{}", + "{}/output/{}", entry.parent().unwrap().to_str().unwrap(), entry.file_name().unwrap().to_str().unwrap() ) @@ -259,7 +259,7 @@ pub async fn class2rgb(dataset_path: &String, rgb_list: &str) { if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -268,7 +268,7 @@ pub async fn class2rgb(dataset_path: &String, rgb_list: &str) { .unwrap() .map(|x| x.unwrap().path()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } @@ -331,7 +331,7 @@ pub async fn class2rgb(dataset_path: &String, rgb_list: &str) { imwrite( format!( - "{}\\output\\{}", + "{}/output/{}", entry.parent().unwrap().to_str().unwrap(), entry.file_name().unwrap().to_str().unwrap() ) @@ -360,7 +360,7 @@ pub async fn class2rgb(dataset_path: &String, rgb_list: &str) { std::mem::drop(header_span_enter); std::mem::drop(header_span); tracing::info!("All done"); - tracing::info!("Saved to {}\\output\\", dataset_path.to_str().unwrap()); + tracing::info!("Saved to {}/output/", dataset_path.to_str().unwrap()); } pub async fn rgb2class(dataset_path: &String, rgb_list: &str) { @@ -369,7 +369,7 @@ pub async fn rgb2class(dataset_path: &String, rgb_list: &str) { if dataset_path.is_file() { entries.push(dataset_path.clone()); fs::create_dir_all(format!( - "{}\\output\\", + "{}/output/", dataset_path.parent().unwrap().to_str().unwrap() )) .expect_or_log("Failed to create directory"); @@ -379,7 +379,7 @@ pub async fn rgb2class(dataset_path: &String, rgb_list: &str) { .map(|x| x.unwrap().path()) .filter(|x| x.is_file()) .collect(); - fs::create_dir_all(format!("{}\\output\\", dataset_path.to_str().unwrap())) + fs::create_dir_all(format!("{}/output/", dataset_path.to_str().unwrap())) .expect_or_log("Failed to create directory"); } @@ -447,7 +447,7 @@ pub async fn rgb2class(dataset_path: &String, rgb_list: &str) { imwrite( format!( - "{}\\output\\{}", + "{}/output/{}", entry.parent().unwrap().to_str().unwrap(), entry.file_name().unwrap().to_str().unwrap() ) @@ -480,7 +480,7 @@ pub async fn rgb2class(dataset_path: &String, rgb_list: &str) { tracing::info!("All done"); tracing::info!( - "Saved to {}\\output\\", + "Saved to {}/output/", dataset_path .parent() .expect_or_log("Get parent error") diff --git a/src/yolo/dataset.rs b/src/yolo/dataset.rs index 392b20f..883a76b 100644 --- a/src/yolo/dataset.rs +++ b/src/yolo/dataset.rs @@ -56,19 +56,19 @@ pub async fn split_dataset(dataset_path: &String, train_ratio: &f32) { let valid_data = data[train_count as usize..].to_vec(); fs::write( - format!("{}\\..\\val.txt", dataset_path), + format!("{}/../val.txt", dataset_path), valid_data.concat(), ) .unwrap(); fs::write( - format!("{}\\..\\train.txt", dataset_path), + format!("{}/../train.txt", dataset_path), train_data.concat(), ) .unwrap(); tracing::info!("Train dataset length: {}", train_data.len()); - tracing::info!("Saved to {}\\..\\train.txt", dataset_path); + tracing::info!("Saved to {}/../train.txt", dataset_path); tracing::info!("Valid dataset length: {}", valid_data.len()); - tracing::info!("Saved to {}\\..\\val.txt", dataset_path); + tracing::info!("Saved to {}/../val.txt", dataset_path); tracing::info!("Dataset split done"); }