python 调用类时报错:TypeError: get_input() missing 1 required positional argument: ‘name‘

在调用类时,报错了,说出现缺少必要参数’xxx’,但是在调用的时候,已经设置了对应的参数了,还是一些小问题。由于没有实例化引起的。
代码如下:

class Net:

    def __init__(self,
                 net_path: str = "./net/",
                 ):
		sym, arg_params, aux_params = mx.model.load_checkpoint(
            f"{net_path}models/model",
            0

		...
		
        )
    def get_input(self, face_img, name):
        detected = self.detector.detect_face(face_img, det_type=self.det)
        
        if detected is None:
            return None
            
        bbox, points = detected
        print('bbox:', bbox)
        # print('points:',points)
        if bbox.shape[0] == 0:
            return None

        (startX, startY, endX, endY, _) = bbox[0].astype("int")
        cropimg = face_img[startY:endY, startX:endX]
        cropimg = cv2.resize(cropimg, (112, 112))
        cv2.imwrite('./' + str(name) + '_new.jpg', cropimg)
        ...
        return cropimg
  • 调用时如果用以下的方法就会报错:
img_input = Net.get_input(img_input, name)

报错:
TypeError: get_input() missing 1 required positional argument: ‘name’

  • 解决的方法很简单,在调用类时加个(),把对应的类实例化就可以了。
img_input = Net().get_input(img_input, name)

你可能感兴趣的:(Python,python)