mirror of
https://github.com/kristoferssolo/Traffic-Light-Detector.git
synced 2025-10-21 20:00:36 +00:00
Updated paths
This commit is contained in:
parent
5881607373
commit
9341c78ed8
@ -13,6 +13,6 @@ def detect_traffic_light_color_image() -> None:
|
|||||||
model_traffic_lights_nn = keras.models.load_model(str(MODEL_PATH))
|
model_traffic_lights_nn = keras.models.load_model(str(MODEL_PATH))
|
||||||
|
|
||||||
# Go through all image files, and detect the traffic light color.
|
# Go through all image files, and detect the traffic light color.
|
||||||
for file in Path.iterdir(IMAGES_IN_PATH):
|
for file in IMAGES_IN_PATH.iterdir():
|
||||||
image, out, file_name = perform_object_detection(load_ssd_coco(), file, save_annotated=True, model_traffic_lights=model_traffic_lights_nn)
|
image, out, file_name = perform_object_detection(load_ssd_coco(), file, save_annotated=True, model_traffic_lights=model_traffic_lights_nn)
|
||||||
logger.info(f"{file} {out}")
|
logger.info(f"{file} {out}")
|
||||||
|
|||||||
@ -14,7 +14,7 @@ from loguru import logger
|
|||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def extract_traffic_lights() -> None:
|
def extract_traffic_lights() -> None:
|
||||||
files = Path.iterdir(INPUT_PATH)
|
files = INPUT_PATH.iterdir()
|
||||||
|
|
||||||
# Load the object detection model
|
# Load the object detection model
|
||||||
this_model = load_ssd_coco()
|
this_model = load_ssd_coco()
|
||||||
@ -68,7 +68,7 @@ def extract_traffic_lights() -> None:
|
|||||||
traffic_light = cv2.cvtColor(traffic_light, cv2.COLOR_RGB2BGR)
|
traffic_light = cv2.cvtColor(traffic_light, cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
# Store the cropped image in a folder named 'traffic_light_cropped'
|
# Store the cropped image in a folder named 'traffic_light_cropped'
|
||||||
cv2.imwrite(str(Path.joinpath(CROPPED_IMAGES_PATH, f"{traffic_light_count}.jpg")), traffic_light)
|
cv2.imwrite(str(CROPPED_IMAGES_PATH.joinpath(f"{traffic_light_count}.jpg")), traffic_light)
|
||||||
|
|
||||||
# Increment the number of traffic lights by 1
|
# Increment the number of traffic lights by 1
|
||||||
traffic_light_count += 1
|
traffic_light_count += 1
|
||||||
|
|||||||
@ -87,7 +87,7 @@ def load_ssd_coco() -> tf.saved_model.LoadOptions:
|
|||||||
@logger.catch
|
@logger.catch
|
||||||
def save_image_annotated(image_rgb, file_name: Path, output, model_traffic_lights=None) -> None:
|
def save_image_annotated(image_rgb, file_name: Path, output, model_traffic_lights=None) -> None:
|
||||||
"""Annotate the image with the object types, and generate cropped images of traffic lights."""
|
"""Annotate the image with the object types, and generate cropped images of traffic lights."""
|
||||||
output_file = Path.joinpath(IMAGES_OUT_PATH, file_name.name)
|
output_file = IMAGES_OUT_PATH.joinpath(file_name.name)
|
||||||
|
|
||||||
# For each bounding box that was detected
|
# For each bounding box that was detected
|
||||||
for idx, (box, object_class) in enumerate(zip(output["boxes"], output["detection_classes"])):
|
for idx, (box, object_class) in enumerate(zip(output["boxes"], output["detection_classes"])):
|
||||||
|
|||||||
@ -5,31 +5,31 @@ from loguru import logger
|
|||||||
|
|
||||||
|
|
||||||
BASE_PATH = Path(__file__).resolve().parent.parent.parent
|
BASE_PATH = Path(__file__).resolve().parent.parent.parent
|
||||||
MODEL_PATH = Path.joinpath(BASE_PATH, "model.h5")
|
MODEL_PATH = BASE_PATH.joinpath("model.h5")
|
||||||
LOGS_PATH = Path.joinpath(BASE_PATH, ".logs")
|
LOGS_PATH = BASE_PATH.joinpath(".logs")
|
||||||
ASSETS_PATH = Path.joinpath(BASE_PATH, "assets")
|
ASSETS_PATH = BASE_PATH.joinpath("assets")
|
||||||
|
|
||||||
VALID_PATH = Path.joinpath(ASSETS_PATH, "out_valid")
|
VALID_PATH = ASSETS_PATH.joinpath("out_valid")
|
||||||
|
|
||||||
DETECTION_PATH = Path.joinpath(ASSETS_PATH, "detection")
|
DETECTION_PATH = ASSETS_PATH.joinpath("detection")
|
||||||
IMAGES_IN_PATH = Path.joinpath(DETECTION_PATH, "images_in")
|
IMAGES_IN_PATH = DETECTION_PATH.joinpath("images_in")
|
||||||
IMAGES_OUT_PATH = Path.joinpath(DETECTION_PATH, "images_out")
|
IMAGES_OUT_PATH = DETECTION_PATH.joinpath("images_out")
|
||||||
VIDEOS_IN_PATH = Path.joinpath(DETECTION_PATH, "videos_in")
|
VIDEOS_IN_PATH = DETECTION_PATH.joinpath("videos_in")
|
||||||
VIDEOS_OUT_PATH = Path.joinpath(DETECTION_PATH, "videos_out")
|
VIDEOS_OUT_PATH = DETECTION_PATH.joinpath("videos_out")
|
||||||
|
|
||||||
DATESET_PATH = Path.joinpath(ASSETS_PATH, "dataset")
|
DATESET_PATH = ASSETS_PATH.joinpath("dataset")
|
||||||
GREEN_PATH = Path.joinpath(DATESET_PATH, "0_green")
|
GREEN_PATH = DATESET_PATH.joinpath("0_green")
|
||||||
YELLOW_PATH = Path.joinpath(DATESET_PATH, "1_yellow")
|
YELLOW_PATH = DATESET_PATH.joinpath(DATESET_PATH, "1_yellow")
|
||||||
RED_PATH = Path.joinpath(DATESET_PATH, "2_red")
|
RED_PATH = DATESET_PATH.joinpath("2_red")
|
||||||
NOT_PATH = Path.joinpath(DATESET_PATH, "3_not")
|
NOT_PATH = DATESET_PATH.joinpath("3_not")
|
||||||
|
|
||||||
EXTRACTION_PATH = Path.joinpath(ASSETS_PATH, "extraction")
|
EXTRACTION_PATH = ASSETS_PATH.joinpath("extraction")
|
||||||
CROPPED_IMAGES_PATH = Path.joinpath(EXTRACTION_PATH, "cropped")
|
CROPPED_IMAGES_PATH = EXTRACTION_PATH.joinpath("cropped")
|
||||||
INPUT_PATH = Path.joinpath(EXTRACTION_PATH, "input")
|
INPUT_PATH = EXTRACTION_PATH.joinpath("input")
|
||||||
|
|
||||||
|
|
||||||
PATHS = (LOGS_PATH, ASSETS_PATH, VALID_PATH, DETECTION_PATH, IMAGES_IN_PATH, IMAGES_OUT_PATH, VIDEOS_IN_PATH, VIDEOS_OUT_PATH,
|
PATHS = (LOGS_PATH, VALID_PATH, IMAGES_IN_PATH, IMAGES_OUT_PATH, VIDEOS_IN_PATH, VIDEOS_OUT_PATH,
|
||||||
DATESET_PATH, GREEN_PATH, YELLOW_PATH, RED_PATH, NOT_PATH, EXTRACTION_PATH, CROPPED_IMAGES_PATH, INPUT_PATH)
|
GREEN_PATH, YELLOW_PATH, RED_PATH, NOT_PATH, CROPPED_IMAGES_PATH, INPUT_PATH)
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
@ -37,11 +37,11 @@ def create_dirs(fresh: bool = False) -> None:
|
|||||||
if fresh:
|
if fresh:
|
||||||
rmtree(ASSETS_PATH)
|
rmtree(ASSETS_PATH)
|
||||||
rmtree(LOGS_PATH)
|
rmtree(LOGS_PATH)
|
||||||
Path.unlink(MODEL_PATH)
|
MODEL_PATH.unlink()
|
||||||
create_dirs()
|
create_dirs()
|
||||||
logger.info("Deleted all dirs")
|
logger.info("Deleted all dirs")
|
||||||
else:
|
else:
|
||||||
for path in PATHS:
|
for path in PATHS:
|
||||||
if not Path.exists(path):
|
if not path.exists():
|
||||||
Path.mkdir(path)
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
logger.info(f"Created dir {path}")
|
logger.info(f"Created dir {path}")
|
||||||
|
|||||||
@ -130,10 +130,10 @@ def train_traffic_light_color() -> None:
|
|||||||
|
|
||||||
# Load the cropped traffic light images from the appropriate directory
|
# Load the cropped traffic light images from the appropriate directory
|
||||||
|
|
||||||
img_0_green = load_rgb_images(Path.iterdir(GREEN_PATH), shape)
|
img_0_green = load_rgb_images(GREEN_PATH.iterdir(), shape)
|
||||||
img_1_yellow = load_rgb_images(Path.iterdir(YELLOW_PATH), shape)
|
img_1_yellow = load_rgb_images(YELLOW_PATH.iterdir(), shape)
|
||||||
img_2_red = load_rgb_images(Path.iterdir(RED_PATH), shape)
|
img_2_red = load_rgb_images(RED_PATH.iterdir(), shape)
|
||||||
img_3_not_traffic_light = load_rgb_images(Path.iterdir(NOT_PATH), shape)
|
img_3_not_traffic_light = load_rgb_images(NOT_PATH.iterdir(), shape)
|
||||||
|
|
||||||
# Create a list of the labels that is the same length as the number of images in each
|
# Create a list of the labels that is the same length as the number of images in each
|
||||||
# category
|
# category
|
||||||
@ -259,7 +259,7 @@ def train_traffic_light_color() -> None:
|
|||||||
# Create the name of the directory and the file for the validation data set
|
# Create the name of the directory and the file for the validation data set
|
||||||
# After each run, delete this out_valid/ directory so that old files are not
|
# After each run, delete this out_valid/ directory so that old files are not
|
||||||
# hanging around in there.
|
# hanging around in there.
|
||||||
file_name = str(Path.joinpath(VALID_PATH, f"{idx}_{label}_{np.argmax(str(y_value))}.jpg"))
|
file_name = str(VALID_PATH.joinpath(f"{idx}_{label}_{np.argmax(str(y_value))}.jpg"))
|
||||||
image = image_as_ar[0]
|
image = image_as_ar[0]
|
||||||
|
|
||||||
# Reverse the image preprocessing process
|
# Reverse the image preprocessing process
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user