“ translate_factor_x = random.uniform(* self.translate)”中“ self.translate”之前的“ *”是什么?

时间:2019-12-14 06:38:15

标签: python

我在这段代码中看到了这一行:

class RandomTranslate(object):

    def __init__(self, translate = 0.2, diff = False):
        self.translate = translate
        if type(self.translate) == tuple:
            assert len(self.translate) == 2, "Invalid range"  
            assert self.translate[0] > 0 & self.translate[0] < 1
            assert self.translate[1] > 0 & self.translate[1] < 1
        else:
            assert self.translate > 0 and self.translate < 1
            self.translate = (-self.translate, self.translate)
        self.diff = diff

    def __call__(self, img):        
        #Chose a random digit to scale by 
        img_shape = img.shape
        #translate the image
        #percentage of the dimension of the image to translate
        translate_factor_x = random.uniform(*self.translate)
        translate_factor_y = random.uniform(*self.translate)
        if not self.diff:
            translate_factor_y = translate_factor_x
        canvas = np.zeros(img_shape).astype(np.uint8)
        corner_x = int(translate_factor_x*img.shape[1])          ## HERE
        corner_y = int(translate_factor_y*img.shape[0])          ## AND HERE

        #change the origin to the top-left corner of the translated box
        orig_box_cords =  [max(0,corner_y), max(corner_x,0), min(img_shape[0], corner_y + img.shape[0]), min(img_shape[1],corner_x + img.shape[1])]
        mask = img[max(-corner_y, 0):min(img.shape[0], -corner_y + img_shape[0]), max(-corner_x, 0):min(img.shape[1], -corner_x + img_shape[1]),:]
        canvas[orig_box_cords[0]:orig_box_cords[2], orig_box_cords[1]:orig_box_cords[3],:] = mask
        img = canvas
        return img

我也不知道这意味着什么,也无法完全查找它。...github上的整个代码。

0 个答案:

没有答案