Ejemplo n.º 1
0
    def __init__(self, g_pool,visualize=True):
        super().__init__(g_pool)
        self.menu = None

        # Initialize CNN pipeline
        self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")


        # Hand Detector
        self.hand_detector_cfg = {
            'input_size': 225,
            'confidence_thresh': 0.9,
            'max_num_detection': 1,
            'nms_thresh': 0.45,
            'weights_path': os.path.join(weights_path,'hand_detector_model.pkl'),
        }
        self.hand_transform = BaseTransform(self.hand_detector_cfg['input_size'], (117.77, 115.42, 107.29), (72.03, 69.83, 71.43))
        self.hand_detector = ssd_lite.build_ssd_lite(self.hand_detector_cfg)
        self.hand_detector.load_state_dict(torch.load(self.hand_detector_cfg['weights_path'], map_location=lambda storage, loc: storage))
        self.hand_detector.eval().to(self.device)

        # Fingertip Detector
        self.fingertip_detector_cfg = {
            'confidence_thresh': 0.6,
            'weights_path': os.path.join(weights_path, "fingertip_detector_model.pkl"),
        }
        self.fingertip_transform = BaseTransform(64, (121.97, 119.65, 111.42), (67.58, 65.17, 67.72))
        self.fingertip_detector = unet.UNet(num_classes=10, in_channels=3, depth=4, start_filts=32, up_mode='transpose')
        self.fingertip_detector.load_state_dict(torch.load(self.fingertip_detector_cfg['weights_path'], map_location=lambda storage, loc: storage))
        self.fingertip_detector.eval().to(self.device)

        self.collect_tips = False
        self.visualize = visualize
        self.hand_viz = []
        self.finger_viz = []
Ejemplo n.º 2
0
    def __init__(self, g_pool, visualize=True):
        super().__init__(g_pool)
        self.menu = None

        # Initialize CNN pipeline
        self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

        # Hand Detector
        self.hand_detector_cfg = {
            "input_size": 225,
            "confidence_thresh": 0.9,
            "max_num_detection": 1,
            "nms_thresh": 0.45,
            "weights_path": os.path.join(weights_path, "hand_detector_model.pkl"),
        }
        self.hand_transform = BaseTransform(
            self.hand_detector_cfg["input_size"],
            (117.77, 115.42, 107.29),
            (72.03, 69.83, 71.43),
        )
        self.hand_detector = ssd_lite.build_ssd_lite(self.hand_detector_cfg)
        self.hand_detector.load_state_dict(
            torch.load(
                self.hand_detector_cfg["weights_path"],
                map_location=lambda storage, loc: storage,
            )
        )
        self.hand_detector.eval().to(self.device)

        # Fingertip Detector
        self.fingertip_detector_cfg = {
            "confidence_thresh": 0.6,
            "weights_path": os.path.join(weights_path, "fingertip_detector_model.pkl"),
        }
        self.fingertip_transform = BaseTransform(
            64, (121.97, 119.65, 111.42), (67.58, 65.17, 67.72)
        )
        self.fingertip_detector = unet.UNet(
            num_classes=10, in_channels=3, depth=4, start_filts=32, up_mode="transpose"
        )
        self.fingertip_detector.load_state_dict(
            torch.load(
                self.fingertip_detector_cfg["weights_path"],
                map_location=lambda storage, loc: storage,
            )
        )
        self.fingertip_detector.eval().to(self.device)

        self.collect_tips = False
        self.visualize = visualize
        self.hand_viz = []
        self.finger_viz = []