Пример #1
0
def main():
    sock = su.initialize_client('localhost', 7777)

    client = HandClient()

    while True:

        frame = su.recvall_pickle(sock)
        pose = client.get_pose(frame)
        su.sendall_pickle(sock, pose)
Пример #2
0
 def callback(self,rgb):
     rgb = self.cv_bridge.imgmsg_to_cv2(rgb,desired_encoding='bgr8')
     rospy.loginfo_once('send image to client')
     su.sendall_pickle(self.sock,rgb)
     rospy.loginfo_once('receive inference results from client')
     result = su.recvall_pickle(self.sock)
     # result : BODY25 keypoints 
     print(result)
     img_msg = self.cv_bridge.cv2_to_imgmsg(rgb,encoding='bgr8')
     self.result_pub.publish(img_msg)
     rospy.loginfo_once('Published the result as topic. Topic name : /estimation_result')
Пример #3
0
    def send_side_signal(self, side_name):
        request = DyrosRequestType.send_side_signal
        self.logger.info("Request {} to Dyros Module".format(request))
        su.sendall_pickle(self.c_dyros, request)

        response = su.recvall_pickle(self.c_dyros)
        assert response, "Not ready to dyros"

        request = side_name
        su.sendall_pickle(self.c_dyros, request)
        is_success = su.recvall_pickle(self.c_dyros)

        if is_success:
            self.logger.info("Success to send side signal")
        assert is_success, "sdfsfadfasdfsdfsdfsdfsadf"
        return is_success
Пример #4
0
    def send_assembly_sequence(self, assembly_sequence, is_pin_end, is_end):
        request = DyrosRequestType.send_assembly_sequence
        self.logger.info("Request {} to Dyros Module".format(request))

        su.sendall_pickle(self.c_dyros, request)
        response = su.recvall_pickle(self.c_dyros)
        assert response, "Not ready to dyros"
        request = {
            "assembly_sequence": assembly_sequence,
            "is_pin_end": is_pin_end,
            "is_end": is_end
        }
        su.sendall_pickle(self.c_dyros, request)
        is_success = su.recvall_pickle(self.c_dyros)

        if is_success:
            self.logger.info("Success to send sequence")
        assert is_success, "sdfsfadfasdfsdfsdfsdfsadf"
        return is_success
    def send_final_assembly_sequence(self, assembly_sequence, is_end):
        request = DyrosRequestType.send_final_assembly_sequence
        self.logger.info("Request {} to Dyros Module".format(request))
        if not is_end:
            su.sendall_pickle(self.c_dyros, request)
            response = su.recvall_pickle(self.c_dyros)
            assert response, "Not ready to dyros"

            request = assembly_sequence
            su.sendall_pickle(self.c_dyros, request)
            is_success = su.recvall_pickle(self.c_dyros)
        else:
            su.sendall_pickle(self.c_dyros, request)
            response = su.recvall_pickle(self.c_dyros)
            assert response, "Not ready to dyros"

            request = assembly_sequence
            su.sendall_pickle(self.c_dyros, request)
            is_success = su.recvall_pickle(self.c_dyros)
        if is_success:
            self.logger.info("Success to send Final sequence")
        assert is_success, "sdfsfadfasdfsdfsdfsdfsadf"
        return is_success
Пример #6
0
def main(args):

    sock = su.initialize_client('localhost', 7777)

    parser = make_parser()
    args = parser.parse_args(args)
    cfg = grasp_estimator.joint_config(
        args.vae_checkpoint_folder,
        args.evaluator_checkpoint_folder,
    )
    cfg['threshold'] = args.threshold
    cfg['sample_based_improvement'] = 1 - int(args.gradient_based_refinement)
    cfg['num_refine_steps'] = 10 if args.gradient_based_refinement else 20
    estimator = grasp_estimator.GraspEstimator(cfg)
    os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg.gpu)
    sess = tf.Session()
    estimator.build_network()
    estimator.load_weights(sess)

    while True:
        data = su.recvall_pickle(sock)

        print(data.keys())
        for k in data.keys():
            print(k, np.shape(data[k]))

        depth = data['depth']
        image = data['image']
        K = data['intrinsics_matrix']
        # Removing points that are farther than 1 meter or missing depth 
        # values.
        depth[depth == 0] = np.nan
        depth[depth > 1] = np.nan
        pc, selection = backproject(depth, K, return_finite_depth=True, return_selection=True)
        pc_colors = image.copy()
        pc_colors = np.reshape(pc_colors, [-1, 3])
        pc_colors = pc_colors[selection, ::-1]

        # down sampling
        idx = np.random.choice(pc_colors.shape[0], 100000, replace=False)
        pc = pc[idx, :]
        pc_colors = pc_colors[idx, :]

        # Smoothed pc comes from averaging the depth for 10 frames and removing
        # the pixels with jittery depth between those 10 frames.
        object_pc = data['smoothed_object_pc']
        latents = estimator.sample_latents()
        generated_grasps, generated_scores, _ = estimator.predict_grasps(
            sess,
            object_pc,
            latents,
            num_refine_steps=cfg.num_refine_steps,
        )
        print("====>", generated_grasps, generated_scores)
        mlab.figure(bgcolor=(1,1,1))
        if len(generated_grasps) != 0:
            draw_scene(
                pc,
                pc_color=pc_colors,
                grasps=generated_grasps,
                grasp_scores=generated_scores,
            )
            print('close the window to continue to next object . . .')
        mlab.show()
        su.sendall_pickle(sock, [generated_grasps, generated_scores])
    with open(yaml_path) as f:
        params = yaml.load(f, Loader=yaml.FullLoader)
    cfg = setup_cfg(params)
    os.environ["CUDA_VISIBLE_DEVICES"] = params["is_gpu_id"]
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    print("==> Loading CenterMask on", device, params["is_gpu_id"])
    demo = VisualizationDemo(cfg)
    sock = su.initialize_client(params["tcp_ip"],
                                params["centermask_tcp_port"])

    while True:
        img = su.recvall_image(sock)
        predictions, vis_output = demo.run_on_image(img)
        pred_masks = predictions["instances"].pred_masks.cpu().detach().numpy(
        )  # (N, H, W),
        pred_boxes = predictions["instances"].pred_boxes.tensor.cpu().detach(
        ).numpy()  # (x1, y1, x2, y2)
        pred_scores = predictions["instances"].scores.cpu().detach().numpy(
        )  # a vector of N confidence scores.
        pred_classes = predictions["instances"].pred_classes.cpu().detach(
        ).numpy()  # [0, num_categories).
        vis_img = cv2.resize(vis_output.get_image()[:, :, ::-1],
                             (params["width"], params["height"]))
        su.sendall_image(sock, vis_img)
        su.sendall_pickle(sock, pred_masks)
        su.sendall_pickle(sock, pred_boxes)
        su.sendall_pickle(sock, pred_classes)
        su.sendall_pickle(sock, pred_scores)

    s.close()
        params = yaml.load(f, Loader=yaml.FullLoader)

    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
    os.environ["CUDA_VISIBLE_DEVICES"] = params["side_gpu_id"]

    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model = timm.create_model(params["side_model_name"], pretrained=False)
    model.to(device)
    model.eval()
    checkpoint = torch.load(params["side_weight_path"])
    model.load_state_dict(checkpoint)
    transform = T.Compose([
        T.ToTensor(),
        T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    sock = su.initialize_client(params["tcp_ip"], params["side_tcp_port"])

    while True:
        img = su.recvall_image(sock)
        img = cv2.resize(img, (224, 224), interpolation=cv2.INTER_LINEAR)
        img = transform(img).unsqueeze(0)
        output = model(img.to(device))
        topk = (1, )
        maxk = max(topk)
        _, pred = output.topk(maxk, 1, True, True)
        pred = np.bool(pred.t()[0].cpu().detach().numpy())
        su.sendall_pickle(sock, pred)

    sock.close()
Пример #9
0
if __name__ == "__main__":

    sock = su.initialize_client('localhost', 7777)
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model = models.detection.maskrcnn_resnet50_fpn(pretrained=True).to(device)
    model.eval()
    print("Using mask R-CNN with ResNet-50 backbone", device)
    transforms_composed = transforms.Compose([transforms.ToTensor()])

    while True:

        recv_image = su.recvall_image(sock)
        x = transforms_composed(recv_image).unsqueeze(0)
        outputs = model(x.to(device))[0]

        probs = outputs['scores'].cpu().detach().numpy()
        boxes = outputs["boxes"].cpu().detach().numpy()
        labels = outputs["labels"].cpu().detach().numpy()
        masks = outputs["masks"].cpu().detach().numpy()

        keep = probs > 0.5
        probs = probs[keep]
        labels = labels[keep]
        boxes = boxes[keep]
        masks = masks[keep]

        su.sendall_pickle(sock, probs)
        su.sendall_pickle(sock, labels)
        su.sendall_pickle(sock, boxes)
        su.sendall_pickle(sock, masks)
Пример #10
0
from easy_tcp_python2_3 import socket_utils as su
from imagenet_stubs.imagenet_2012_labels import label_to_name


if __name__ == "__main__" :

    sock = su.initialize_client('localhost', 7777)
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model = models.resnet50(pretrained=True).to(device)
    model.eval()
    print("Using ResNet-50", device)
    transforms_composed = transforms.Compose([
            transforms.ToTensor(),
            transforms.Normalize(
            mean=[0.485, 0.456, 0.406],
            std=[0.229, 0.224, 0.225]),
            ])

    while True:
        
        recv_image = su.recvall_image(sock)
        x = transforms_composed(recv_image).unsqueeze(0)
        outputs = model(x.to(device))
        _, preds = torch.max(outputs, 1)
        class_name = label_to_name(preds[0].item())
        su.sendall_pickle(sock, class_name)