Team Ai
Apppublic

delsj/function-gemma

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
image.cpython-312.pyc46 linesDownload Raw Back to __pycache__
1�

2LIi����ddlZddlZddlmZddlZddlmZ	ddl	m3Z4e
ezejzejzZGd�de5�Zy#e$r	ddlm6Z7Y�8wxYw)�N)�Path)�Image)�TrackioMediac�j��eZdZdZdZddededzf�fd�
Zdejdzfd�Z8d	efd9�Z�xZ
S)�TrackioImageae10    Initializes an Image object.11 12    Example:13        ```python14        import trackio15        import numpy as np16        from PIL import Image17 18        # Create an image from numpy array19        image_data = np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)20        image = trackio.Image(image_data, caption="Random image")21        trackio.log({"my_image": image})22 23        # Create an image from PIL Image24        pil_image = Image.new('RGB', (100, 100), color='red')25        image = trackio.Image(pil_image, caption="Red square")26        trackio.log({"red_image": image})27 28        # Create an image from file path29        image = trackio.Image("path/to/image.jpg", caption="Photo from file")30        trackio.log({"file_image": image})31        ```32 33    Args:34        value (`str`, `Path`, `numpy.ndarray`, or `PIL.Image`, *optional*):35            A path to an image, a PIL Image, or a numpy array of shape (height, width, channels).36            If numpy array, should be of type `np.uint8` with RGB values in the range `[0, 255]`.37        caption (`str`, *optional*):38            A string caption for the image.39    z
trackio.imageN�value�captionc�&��t�|�||�d|_t|jt40�s(t
dt41�dt|j�����t|jtj�rI|jjtjk7r"t
d|jj����t|jtjtjz�r|j�d|_yyy)NzInvalid value type, expected z, got z,Invalid value dtype, expected np.uint8, got �png)�super�__init__�_format�42isinstance�_value�TrackioImageSourceType�43ValueError�type�np�ndarray�dtype�uint8�PILImager)�selfrr	�	__class__s   ��>/usr/local/lib/python3.12/dist-packages/trackio/media/image.pyr
zTrackioImage.__init__4s����
�����(�#'����$�+�+�'=�>��/�0F�/G�v�d�SW�S^�S^�N_�M`�a��
��d�k�k�2�:�:�.�4�;�;�3D�3D����3P��>�t�{�{�?P�?P�>Q�R��
�
�t�{�{�B�J�J����$?�@����$� �D�L�%�
A��returnc���	t|jtj�rRtj|j�jd�}t
j|�jd�St|jtj�r|jjd�S	y#t$r}td|j���|�d}~wwxYw)Nr�RGBAzFailed to process image data: )rrrr�asarray�astyper�	fromarray�convertr�	Exceptionr)r�arr�es   r�_as_pilzTrackioImage._as_pilFs���	T��$�+�+�r�z�z�2��j�j����-�4�4�W�=���)�)�#�.�6�6�v�>�>��$�+�+�x�~�~�6��{�{�*�*�6�2�2�7����	T��=�d�k�k�]�K�L�RS�S��	T�s�A5B9�8>B9�9	C �C�C �	file_pathc�j�|j�x}r|j||j��yt|jt44tz�rbtjj|j�r!tj|j|�ytd|j����y)N)�formatzFile not found: )
r'�saverrr�strr�os�path�isfile�shutil�copyr)rr(�pils   r�_save_mediazTrackioImage._save_mediaQs{���,�,�.� �3� ��H�H�Y�t�|�|�H�4�
����S�4�Z�
0��w�w�~�~�d�k�k�*����D�K�K��3� �#3�D�K�K�=�!A�B�B�	1r)N)�__name__�45__module__�__qualname__�__doc__�TYPErr,r
rrr'rr3�
__classcell__)rs@rrrsK����@�D�!�4�!�s�T�z�!�$	����$�.�	�C�T�Crr)r-r0�pathlibr�numpyr�PILrr�trackio.media.mediar�ImportError�media.mediar,rrr�rr�<module>rAs^��	�
���!�)�0�46�t��b�j�j�0�8�>�>�A��GC�<�GC���)�(�)�s�A�A�A