python 出现 " .... Attempt to start .....This probably means...if __name__ == '__main__':cuow

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32846595/article/details/79263009

 当python出现

“ Attempt to start a new process before the current process

            has finished its bootstrapping phase.


            This probably means that you are on Windows and you have
            forgotten to use the proper idiom in the main module:


                if __name__ == '__main__':
                    freeze_support()
                    ...


            The "freeze_support()" line can be omitted if the program

            is not going to be frozen to produce a Windows executable.” 

这是因为多进程原因,解决办法,在你使用多进程的模块前添加   if __name__ == '__main__':

例如:

detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0), num_worker = 4 , accurate_landmark = False)

img = cv2.imread('test.jpg')

# run detector
results = detector.detect_face(img)
if results is not None:
   total_boxes = results[0]
   points = results[1]
    
   # extract aligned face chips
   chips = detector.extract_image_chips(img, points, 144, 0.37)
   for i, chip in enumerate(chips):
     cv2.imshow('chip_'+str(i), chip)
     cv2.imwrite('chip_'+str(i)+'.png', chip)
     draw = img.copy()
   for b in total_boxes:
     cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (255, 255, 255))
   for p in points:
     for i in range(5):
       cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)
   cv2.imshow("detection result", draw)
   cv2.waitKey(0)
需要这样修改

if __name__ == '__main__':
    detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0), num_worker = 4 , accurate_landmark = False)


    img = cv2.imread('test.jpg')




 # run detector
    results = detector.detect_face(img)


    if results is not None:


        total_boxes = results[0]
        points = results[1]
    
        # extract aligned face chips
        chips = detector.extract_image_chips(img, points, 144, 0.37)
        for i, chip in enumerate(chips):
            cv2.imshow('chip_'+str(i), chip)
            cv2.imwrite('chip_'+str(i)+'.png', chip)


        draw = img.copy()
        for b in total_boxes:
            cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (255, 255, 255))


        for p in points:
            for i in range(5):
                cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)


        cv2.imshow("detection result", draw)
        cv2.waitKey(0)  
 就可以了




猜你喜欢

转载自blog.csdn.net/qq_32846595/article/details/79263009