
    2Vh                         d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ 	 d dlmZ  ed      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d	       Zy# e$ r dZY )w xY w)    N)backend)ops)keras_export)draw_bounding_boxes)plot_image_gallery)patchesz-keras.visualization.plot_bounding_box_galleryc                    t         t        d      |xs |
}|xs |
}|xs t        j                         }t	        j
                  |       }t        |      dk7  rt        d|       |dk(  rt	        j                  | d      } t	        j                  |       }t        j                  t        |||	|      }| |||||      }| |||||      }|rg|rt        d      t        j                  t        j                  |      d	z  d
      t        j                  t        j                  |      d	z  d      g}t!        |f||||d|S )a  Plots a gallery of images with bounding boxes.

    This function can display both ground truth and predicted bounding boxes on
    a set of images.  It supports various bounding box formats and can include
    class labels and a legend.

    Args:
        images: A 4D tensor or NumPy array of images. Shape should be
            `(batch_size, height, width, channels)`.
        bounding_box_format: The format of the bounding boxes.
            Refer [keras-io](TODO)
        y_true: A dictionary containing the ground truth bounding boxes and
            labels. Should have the same structure as the `bounding_boxes`
            argument in `keras.visualization.draw_bounding_boxes`.
            Defaults to `None`.
        y_pred: A dictionary containing the predicted bounding boxes and labels.
            Should have the same structure as `y_true`. Defaults to `None`.
        value_range: A tuple specifying the value range of the images
            (e.g., `(0, 255)` or `(0, 1)`). Defaults to `(0, 255)`.
        true_color: A tuple of three integers representing the RGB color for the
            ground truth bounding boxes. Defaults to `(0, 188, 212)`.
        pred_color: A tuple of three integers representing the RGB color for the
            predicted bounding boxes. Defaults to `(255, 235, 59)`.
        line_thickness: The thickness of the bounding box lines. Defaults to 2.
        font_scale: The scale of the font used for labels. Defaults to 1.0.
        text_thickness: The thickness of the bounding box text. Defaults to
            `line_thickness`.
        class_mapping: A dictionary mapping class IDs to class names.  Used f
            or both ground truth and predicted boxes if `ground_truth_mapping`
            and `prediction_mapping` are not provided. Defaults to `None`.
        ground_truth_mapping:  A dictionary mapping class IDs to class names
            specifically for ground truth boxes. Overrides `class_mapping`
            for ground truth. Defaults to `None`.
        prediction_mapping: A dictionary mapping class IDs to class names
            specifically for predicted boxes. Overrides `class_mapping` for
            predictions. Defaults to `None`.
        legend: A boolean indicating whether to show a legend.
            Defaults to `False`.
        legend_handles: A list of matplotlib `Patch` objects to use for the
            legend. If this is provided, the `legend` argument will be ignored.
            Defaults to `None`.
        rows: The number of rows in the image gallery. Required if the images
            are not batched. Defaults to `None`.
        cols: The number of columns in the image gallery. Required if the images
            are not batched. Defaults to `None`.
        data_format: The image data format `"channels_last"` or
            `"channels_first"`. Defaults to the Keras backend data format.
        kwargs: Additional keyword arguments to be passed to
            `keras.visualization.plot_image_gallery`.

    Returns:
       The output of `keras.visualization.plot_image_gallery`.

    Raises:
        ValueError: If `images` is not a 4D tensor/array or if both `legend` a
        nd `legend_handles` are specified.
        ImportError: if matplotlib is not installed
    z~The `plot_bounding_box_gallery` function requires the  `matplotlib` package. Please install it with  `pip install matplotlib`.   z;`images` must be batched 4D tensor. Received: images.shape=channels_first)r            )bounding_box_formatline_thicknesstext_thickness
font_scale)colorclass_mappingz\Only pass `legend` OR `legend_handles` to `keras.visualization.plot_bounding_box_gallery()`.g     o@zGround Truth)r   label
Prediction)value_rangelegend_handlesrowscols)r   ImportErrorr   image_data_formatr   shapelen
ValueError	transposeconvert_to_numpy	functoolspartialr   Patchnparrayr   )imagesr   y_truey_predr   
true_color
pred_colorr   r   r   r   ground_truth_mappingprediction_mappinglegendr   r   r   data_formatkwargsimages_shapeplotted_imagesdraw_fns                         a/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/visualization/plot_bounding_box_gallery.pyplot_bounding_box_galleryr5      s   ` )
 	
 ,<}/@=<!:!:!<K99V$L
<A&&2^5
 	
 &&v|4))&1N/%%G  .	
  ,	
 E 
 MMhhz*U2$ MMhhz*U2"	
 %      )NN)r      )r         )r7      ;   r   g      ?NNNNFNNNN)r"   numpyr%   	keras.srcr   r   keras.src.api_exportr   +keras.src.visualization.draw_bounding_boxesr   *keras.src.visualization.plot_image_galleryr   
matplotlibr   r   r5    r6   r4   <module>rC      s        - K I"
 => 		%S ?S  Gs   A AA