-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcretemask.py
49 lines (39 loc) · 1.61 KB
/
concretemask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import configparser
from pathlib import Path
# Get the directory of the current script
script_dir = Path(__file__).parent.absolute()
# Set the path to config.ini based on the script directory
config_ini_path = script_dir / "config.ini"
print(config_ini_path)
# Read parameters from config.ini using Python
config = configparser.ConfigParser()
config.read(config_ini_path)
raw_directory = config["Settings"]["image_path"]
mask_directory = config["CrackSegmentation"]["mask_directory"].replace("crackmask", "concretemask")
config_param = config["CrackSegmentation"]["config"]
model = "saved/UperNet/01-17_12-56/best_model.pth" # concreteNet
print(f"RAW_DIR={raw_directory}")
print(f"MASK_DIR={mask_directory}")
print(f"CONFIG={config_param}")
print(f"MODEL={model}")
# Ensure the mask_directory exists
os.makedirs(mask_directory, exist_ok=True)
print(f"Ensured existence of directory: {mask_directory}")
# Get the model path
model_path = Path("/home/roboticslab/Developer/pytorch_concrete_flaws_segmentation") / model
print(f"MODEL_PATH={model_path}")
# Define the directory where inference.py is located
pytorch_segmentation_dir = "/home/roboticslab/Developer/pytorch_concrete_flaws_segmentation"
# Combined command to activate conda environment and run the Python script
# source '/home/roboticslab/miniconda3/etc/profile.d/conda.sh' && \
# conda activate visualinspection113 && \
command = f"""
cd "{pytorch_segmentation_dir}" && python3 inference.py \
--config "{config_param}" \
--model "{model_path}" \
--images "{raw_directory}" \
--output "{mask_directory}" \
--extension jpg png JPG
"""
os.system(command)