Revision 2b019233d6851facadec8e9215cc805eef47932c authored by Changjian Chen on 20 May 2024, 01:52:04 UTC, committed by Changjian Chen on 20 May 2024, 01:52:04 UTC
1 parent 08a8fb3
__init__.cpython-36.pyc
3
�L`� � @ s� d dl mZmZmZmZmZ d dlmZmZm Z d dl
mZmZm
Z
mZ d dlT ddlZddlZddlZddlmZ ddlmZ d d
� Zdd� Zd
d� ZG dd� de�Zdd� ZG dd� d�ZdS )� )�
COCODetection�COCOAnnotationTransform�COCO_CLASSES� COCO_ROOT�
get_label_map)�COCO17Detection�COCO17_ROOT�COCO17AnnotationTransform)�VOCDetection�VOCAnnotationTransform�VOC_ROOT�VOC_CLASSES)�*� N)�Sampler)�pad_sequencec C s� g }g }g }g }xb| D ]Z}|j |d � |j tj|d �� |j tj|d �� t|�dkr|j tj|d �� qW t|�dkr�tj|d�|fS tj|d�||tj|d�fS dS )a� Custom collate fn for dealing with batches of images that have a different
number of associated object annotations (bounding boxes).
Arguments:
batch: (tuple) A tuple of tensor images and lists of annotations
Return:
A tuple containing:
1) (tensor) batch of images stacked on their 0 dim
2) (list of tensors) annotations for a given image are stacked on
0 dim
r r � � � N)�append�torch�FloatTensor�len�stack)�batch�targets�imgs�semis�image_level_target�sample� r �,/data/changjian/WSL/CSD-SSD/data/__init__.py�detection_collate s
r" c C s� g }g }g }g }g }xj| D ]b}|j |d � |j tj|d �� |j tj|d �� |j tj|d �� |j tj|d �� qW tj|d�||tj|d�|fS )Nr r r r r )r r r r )r r r r r Zdetr r r r! �finetune_detection_collate- s
r# c C s� g }g }g }g }xJ| D ]B}|j |d � |j |d � |j |d � |j tj|d �� qW t|dd�tj|�t|dd�tj|d�fS )Nr r r r T)Zbatch_first)r r r r r )r Z
text_featuresZimage_featuresr Zmasksr r r r! �text_collate> s
r$ c @ s. e Zd Zddd�Zdd� Zdd� Zdd � Zd
S )�VOCBatchSamplerr c C s� t |t�stdj|���t |t�s*|dkr8tdj|���t |t�sPtdj|���|| _|| _|| _|| _|| _ t
|| | j �| _| j| j | _|| _
d S )NzMsampler should be an instance of torch.utils.data.Sampler, but got sampler={}r zFbatch_size should be a positive integeral value, but got batch_size={}z9drop_last should be a boolean value, but got drop_last={})�
isinstancer �
ValueError�format�bool�sampler�
batch_size� drop_last�super_threshold�supervise_percent�int�
supervise_num�unsupervise_num�only_supervise)�selfr* r+ r, r- r. r2 �batch_super_timesr r r! �__init__M s$
zVOCBatchSampler.__init__c C s
|| _ d S )N)r2 )r3 r2 r r r! �set_only_supervisec s z"VOCBatchSampler.set_only_supervisec c s | j rXg }x0| jD ]&}|j|� t|�| jkr|V g }qW t|�dkrV| j rV|V n�g }g }x�| jD ]x}|| jkr�t|�| jk r�|j|� n"|| jkr�t|�| jk r�|j|� t|�| jkrht|�| jkrh|| V g }g }qhW t|| �dko�| j �r|| V d S )Nr ) r2 r* r r r+ r, r- r1 r0 )r3 r ZidxZsuper_batchZ
unsuper_batchr r r! �__iter__n s,
zVOCBatchSampler.__iter__c C s4 | j rt| j�| j S t| j�| j d | j S d S )Nr )r, r r* r+ )r3 r r r! �__len__� s zVOCBatchSampler.__len__N)r )�__name__�
__module__�__qualname__r5 r6 r7 r8 r r r r! r% L s
r% c C s0 t j| ||f�jtj�}||8 }|jtj�}|S )N)�cv2ZresizeZastype�np�float32)�image�size�mean�xr r r! �base_transform� s rC c @ s e Zd Zdd� Zddd�ZdS )�
BaseTransformc C s || _ tj|tjd�| _d S )N)Zdtype)r@ r= �arrayr> rA )r3 r@ rA r r r! r5 � s zBaseTransform.__init__Nc C s t || j| j�||fS )N)rC r@ rA )r3 r? ZboxesZlabelsr r r! �__call__� s zBaseTransform.__call__)NN)r9 r: r; r5 rF r r r r! rD � s rD )Zcocor r r r r Zcoco17r r r Zvocr
r r r
�configr r<