Skip to content

Commit

Permalink
fix: fix wrong path escape char on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
4o3F committed Jan 10, 2025
1 parent e38d00b commit 1c8bda9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
32 changes: 16 additions & 16 deletions src/common/augment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
);
}
Expand All @@ -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()
);
}
Expand Down Expand Up @@ -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()
);
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/common/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/common/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
10 changes: 5 additions & 5 deletions src/common/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
28 changes: 14 additions & 14 deletions src/common/remap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/yolo/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 1c8bda9

Please sign in to comment.