CoolFace
Apppublic

midlajvalappil/Real-time_Object_Detection_with_YOLO

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
config.cpython-312.pyc76 linesDownload Raw Back to __pycache__
1�

2h9}h %��8�dZddlZddlmZddlmZmZmZddlZddl	Z	e	je	j��e	je
�ZeGd�d��ZeGd�d	��ZeGd3�d��ZeGd�d
��ZGd�d�Ze�Zy)zF4Configuration Module5Handles application configuration and settings.6�N)�	dataclass)�Dict�Any�List)�levelc�J�eZdZUdZdZeed<dZeed<dZ	e7ed<dZeed	<y8)�DetectionConfigz#Configuration for object detection.�9yolov8n.pt�10model_nameg�?�confidence_threshold�d�max_detectionsg�������?�
nms_thresholdN)�__name__�11__module__�__qualname__�__doc__r�str�__annotations__r�floatr�intr���F/home/midlaj/Documents/Object Detection using YOLO/src/utils/config.pyr	r	s.��-�"�J��"�"%��%�%��N�C���M�5�rr	c�J�eZdZUdZdZeed<dZeed<dZeed<dZ	eed	<y12)�CameraConfigz"Configuration for camera settings.r�camera_indexi��frame_widthi��frame_height��13fps_targetN)14rrrrrrrrrr!rrrrrs-��,��L�#���K����L�#���J��rrc�X�eZdZUdZdZeed<dZeed<dZ	e15ed<dZe16ed<dZe17ed	<y18)�UIConfigzConfiguration for UI settings.z$Real-time Object Detection with YOLO�19page_titlei,�
sidebar_widthT�show_fps�20show_stats�show_confidenceN)
rrrrr$rrr%rr&�boolr'r(rrrr#r# s7��(�<�J��<��M�3���H�d���J��� �O�T� rr#c�J�eZdZUdZdZeed<dZeed<dZe	ed<dZ21eed<y	)22�PerformanceConfigz'Configuration for performance settings.��detection_intervalr �max_fpsT�23enable_gpu�24batch_sizeN)rrrrr-rrr.r/r)r0rrrr+r+)s.��1������G�S���J����J��rr+c�\�eZdZdZddefd�Zd�Zd�Zdedeee	ffd�Z25deefd	�Zd26�Z
y)
�	AppConfigz%Main application configuration class.�config_filec���||_t�|_t�|_t�|_t�|_gd�|_	dddddd�|_27|j�y)z�28        Initialize application configuration.29        30        Args:31            config_file (str): Path to configuration file32        )r33z34yolov8s.ptz35yolov8m.ptz36yolov8l.ptz37yolov8x.ptz6YOLOv8 Nano - Fastest, good for real-time applicationsz*YOLOv8 Small - Balanced speed and accuracyz/YOLOv8 Medium - Better accuracy, moderate speedz.YOLOv8 Large - High accuracy, slower inferencez8YOLOv8 Extra Large - Highest accuracy, slowest inferenceN)r3r	�	detectionr�camerar#�uir+�performance�available_models�model_descriptions�load_config)�selfr3s  r�__init__zAppConfig.__init__4sg��'���(�*���"�n����*���,�.���!38���S�F�K�J�T�#39���	
���rc�8	�tjj|j��r	t	|jd�5}tj|�}ddd�dvr�|d}|jd|jj�|j_	|jd|jj�|j_40|jd|jj�|j_|jd|jj�|j_d|vr�|d}|jd	|jj�|j_|jd41|jj�|j_|jd|jj �|j_|jd|jj"�|j_d
|v�r|d
}|jd|j$j&�|j$_|jd|j$j(�|j$_|jd|j$j*�|j$_|jd|j$j,�|j$_|jd|j$j.�|j$_d|vr�|d}|jd|j0j2�|j0_|jd|j0j4�|j0_|jd|j0j6�|j0_|jd|j0j8�|j0_t:j=d|j���yt:j=d�y#1swY���xYw#t>$r@}t:jAdtC|����t:j=d�Yd}~yd}~wwxYw)zLoad configuration from file.�rNr5rrrrr6rrrr!r7r$r%r&r'r(r8r-r.r/r0zConfiguration loaded from zError loading configuration: zUsing default configurationz,Configuration file not found, using defaults)"�os�path�existsr3�open�json�load�getr5rrrrr6rrrr!r7r$r%r&r'r(r8r-r.r/r0�logger�info�	Exception�errorr)r<�f�config_data�detection_data�camera_data�ui_data�	perf_data�es        rr;zAppConfig.load_configUsv��
�7�7�>�>�$�*�*�+�)
;��$�*�*�C�0�/�A�"&�)�)�A�,�K�/��+�-�%0��%=�N�0>�0B�0B�<�QU�Q_�Q_�Qj�Qj�0k�D�N�N�-�:H�:L�:L�Mc�ei�es�es�fI�fI�;J�D�N�N�7�4B�4F�4F�GW�Y]�Yg�Yg�Yv�Yv�4w�D�N�N�1�3A�3E�3E�o�W[�We�We�Ws�Ws�3t�D�N�N�0��{�*�"-�h�"7�K�/:���~�t�{�{�Og�Og�/h�D�K�K�,�.9�o�o�m�T�[�[�Md�Md�.e�D�K�K�+�/:���~�t�{�{�Og�Og�/h�D�K�K�,�-8�_�_�\�4�;�;�Ka�Ka�-b�D�K�K�*��;�&�)�$�/�G�)0���\�4�7�7�CU�CU�)V�D�G�G�&�,3�K�K�����I^�I^�,_�D�G�G�)�'.�{�{�:�t�w�w�?O�?O�'P�D�G�G�$�)0���\�4�7�7�CU�CU�)V�D�G�G�&�.5�k�k�:K�T�W�W�Md�Md�.e�D�G�G�+�!�K�/� +�M� :�I�:C�-�-�H\�^b�^n�^n�_B�_B�;C�D�$�$�7�/8�}�}�Y��HX�HX�H`�H`�/a�D�$�$�,�2;�-�-��d�N^�N^�Ni�Ni�2j�D�$�$�/�2;�-�-��d�N^�N^�Ni�Ni�2j�D�$�$�/����8��9I�9I�8J�K�L�
�K�K�F�G�U/�/��L�
;����<�S��V�H�E�F����9�:�:��
;�s0�Q�Q�OQ�Q
�Q�	R�6R�Rc��	|jj|jj|jj|jjd�|j42j|j43j|j44j|j45jd�|jj|jj|jj|jj|jjd�|j j"|j j$|j j&|j j(d�d�}t+|j,d�5}t/j0||d��d	d	d	�t2j5d46|j,���y	#1swY�,xYw#t6$r+}t2j9dt;|����Yd	}~y	d	}~wwxYw)z#Save current configuration to file.)rrrr)rrrr!)r$r%r&r'r()r-r.r/r0)r5r6r7r8�w�)�indentNzConfiguration saved to zError saving configuration: )r5rrrrr6rrrr!r7r$r%r&r'r(r8r-r.r/r0rCr3rD�dumprGrHrIrJr)r<rLrKrQs    r�save_configzAppConfig.save_config�s���#	B�#'�.�.�";�";�,0�N�N�,O�,O�&*�n�n�&C�&C�%)�^�^�%A�%A�	�%)�K�K�$<�$<�#'�;�;�#:�#:�$(�K�K�$<�$<�"&�+�+�"8�"8�	�#'�'�'�"4�"4�%)�W�W�%:�%:� $��� 0� 0�"&�'�'�"4�"4�'+�w�w�'>�'>��+/�*:�*:�*M�*M�#�/�/�7�7�"&�"2�"2�"=�"=�"&�"2�"2�"=�"=�	 �)�K�8�d�&�&��,�
4���	�	�+�q��3�
4�
�K�K�1�$�2B�2B�1C�D�E�
4�
4��47�	B��L�L�7��A��x�@�A�A��	B�s0�FG�G�!*G�G�G�	H�!!H�Hr�returnc�Z�||jj|d�||jvd�S)z�48        Get information about a model.49        50        Args:51            model_name (str): Name of the model52            53        Returns:54            Dict[str, Any]: Model information55        z
Unknown model)�name�description�	available)r:rFr9)r<rs  r�get_model_infozAppConfig.get_model_info�s5����2�2�6�6�z�?�S�#�t�'<�'<�<�56�	57rc�P�g}d|jjcxkrdksn|jd�|jjdkr|jd�d|jjcxkrdksn|jd�|j58jdkr|jd�|j59jdks|j60jdkr|jd�|j61jdkr|jd	�|jjdkr|jd62�|jjdkr|jd�|jjdkr|jd�|S)
z�63        Validate current configuration.64        65        Returns:66            List[str]: List of validation errors (empty if valid)67        gg�?z0Confidence threshold must be between 0.0 and 1.0rzMax detections must be positivez)NMS threshold must be between 0.0 and 1.0z!Camera index must be non-negativez!Frame dimensions must be positivezFPS target must be positivez#Detection interval must be positivezMax FPS must be positivezBatch size must be positive)r5r�appendrrr6rrrr!r8r-r.r0)r<�errorss  r�validate_configzAppConfig.validate_config�sL�����t�~�~�:�:�A�c�A��M�M�L�M��>�>�(�(�A�-��M�M�;�<��t�~�~�3�3�:�s�:��M�M�E�F��;�;�#�#�a�'��M�M�=�>��;�;�"�"�a�'�4�;�;�+C�+C�q�+H��M�M�=�>��;�;�!�!�Q�&��M�M�7�8����.�.�!�3��M�M�?�@����#�#�q�(��M�M�4�5����&�&�!�+��M�M�7�8��
rc��t�|_t�|_t	�|_t
�|_tjd�y)z&Reset configuration to default values.zConfiguration reset to defaultsN)68r	r5rr6r#r7r+r8rGrH)r<s r�reset_to_defaultszAppConfig.reset_to_defaults�s6��(�*���"�n����*���,�.������5�6rN)zconfig.json)rrrrrr=r;rWrrr]rrarcrrrr2r21sQ��/��C��B.H�`%B�N69��70��c�3�h��71� '��c��'�R7rr2)rr@�dataclassesr�typingrrrrD�logging�basicConfig�INFO�	getLoggerrrGr	rr#r+r2�72app_configrrr�<module>rks����7374�!�"�"�������'�,�,�'�	��	�	�8�	$��75� � �� �������!�!��!������z7�z7�|�[�76r