Exemple #1
0
    def test_dataset_manager(self):
        dataset = GroundTruthDataset(length=260)
        lengths = (200, 30, 30)
        dataset_manager = SupervisedDatasetManager(dataset,
                                                   lenghts=lengths,
                                                   num_workers=WORKERS_COUNT)

        self.assertEqual(len(dataset_manager.get_train_dataset()), lengths[0])
        self.assertEqual(len(dataset_manager.get_test_dataset()), lengths[1])
        self.assertEqual(len(dataset_manager.get_validation_dataset()),
                         lengths[2])
        batches = dataset_manager.get_train_batches(20)
        for X, y in batches:
            self.assertEqual(X.shape, torch.Size([20, 3, 128, 384]))
            self.assertEqual(y.shape, torch.Size([20, 1, 128, 384]))
            self.assertEqual(X.dtype, torch.float32)
            self.assertEqual(y.dtype, torch.uint8)
            break

        batches = dataset_manager.get_validation_batches(20)
        for X, y in batches:
            self.assertEqual(X.shape, torch.Size([20, 3, 128, 384]))
            self.assertEqual(y.shape, torch.Size([20, 1, 128, 384]))
            self.assertEqual(X.dtype, torch.float32)
            self.assertEqual(y.dtype, torch.uint8)
            break

        batches = dataset_manager.get_test_batches(20)
        for X, y in batches:
            self.assertEqual(X.shape, torch.Size([20, 3, 128, 384]))
            self.assertEqual(y.shape, torch.Size([20, 1, 128, 384]))
            self.assertEqual(X.dtype, torch.float32)
            self.assertEqual(y.dtype, torch.uint8)
            break
 def test_supervised_depth_problem(self):
     dataset = GroundTruthDataset(length=260)
     print (dataset._names)
     lengths = (200, 30, 30)
     dataset_manager = SupervisedDatasetManager(dataset, lengths=lengths, num_workers=WORKERS_COUNT)
     model = DepthNet(max_depth=2., min_depth=1.0).cuda()
     optimizer_manger = OptimizerManager()
     criterion = SupervisedCriterion(0.01)
     handler = TrainingProcessHandler(mlflow_tags={"name": "test"})
     problem = SupervisedDepthProblem(model, criterion, optimizer_manger, dataset_manager, handler,
                                      batch_size=1)
     problem.train(1)
Exemple #3
0
 def calculate_metrics(self):
     self._model.eval()
     metrics = {}
     depth_dataset = GroundTruthDataset(length=self._length, velodyne=False)
     s_dataset_manager = SupervisedDatasetManager(depth_dataset,
                                                  lengths=self._lengths)
     batches = s_dataset_manager.get_test_batches(self._batch_size)
     for img, true in s_dataset_manager.get_test_dataset():
         pred = self.get_depth_from_image(img)
         self.append_to_metrics(metrics,
                                self.compute_depth_errors(pred, true))
     final_metrics = {}
     for key in metrics.keys():
         final_metrics[key] = np.array(metrics[key]).mean()
     return final_metrics
Exemple #4
0
            "lambda_position": args.lambda_position,
            "lambda_rotation": args.lambda_rotation,
            "lambda_s": args.lambda_s,
            "lambda_disparity": args.lambda_disparity
        })
    optimizer_manager = OptimizerManager(lr=args.lr)
    problem = UnsupervisedDepthProblem(model,
                                       criterion,
                                       optimizer_manager,
                                       dataset_manager,
                                       handler,
                                       batch_size=args.batch,
                                       name="undeepvo")

elif args.method == "supervised":
    dataset = GroundTruthDataset(length=lengths)
    dataset_manager = SupervisedDatasetManager(dataset, lenghts=lengths)

    model = DepthNet(args.max_depth).cuda()

    criterion = SupervisedCriterion(args.supervised_lambda)

    handler = TrainingProcessHandler(
        enable_mlflow=True,
        mlflow_tags={"name": args.mlflow_tags_name},
        mlflow_parameters={
            "image_step": args.frames_range[2],
            "max_depth": args.max_depth,
            "epoch": args.epoch,
            "supervised_lambda": args.supervised_lambda
        })
 def test_dataset(self):
     length = 1000
     dataset = GroundTruthDataset(velodyne=True, length=length)
     self.assertEqual(dataset.get_length(), length)
     idx = 0
     self.assertIsInstance(dataset.get_image(idx), np.ndarray)
     self.assertIsInstance(dataset.get_depth(idx), np.ndarray)
     # image_size
     self.assertIsInstance(dataset.get_image_size(), tuple)
     self.assertEqual(len(dataset.get_image_size()), 2)
     self.assertTrue(
         dataset.get_image_size()[0] < dataset.get_image_size()[1])
     # image_params
     self.assertIsInstance(dataset.get_image(idx).shape, tuple)
     self.assertEqual(len(dataset.get_image(idx).shape), 3)
     # depth_params
     self.assertIsInstance(dataset.get_depth(idx).shape, tuple)
     self.assertEqual(len(dataset.get_depth(idx).shape), 2)