Exemplo n.º 1
0
def get_data(prefix, part_rangestart, finalize, debug_run):  # pylint: disable=too-many-branches
    """Get the data."""
    rangestart = part_rangestart
    rangeend = 10 if part_rangestart == 0 else part_rangestart + 3
    train_f = h5py.File(
        path.join(DIRECT3D_DATA_FP, '91', '500', prefix, 'train.hdf5'))
    train_dset = train_f['2dto3d']
    if debug_run:
        train_dta = np.array(train_dset[:10000])
    else:
        train_dta = np.array(train_dset)
    preprocess(train_dta)
    #add_noise(train_dta)
    val_f = h5py.File(
        path.join(DIRECT3D_DATA_FP, '91', '500', prefix, 'val.hdf5'))
    val_dset = val_f['2dto3d']
    if debug_run:
        val_dta = np.array(val_dset[:10])
    else:
        val_dta = np.array(val_dset)
    preprocess(val_dta)
    if finalize:
        train_dta = np.vstack((train_dta, val_dta))
        val_f = h5py.File(
            path.join(DIRECT3D_DATA_FP, '91', '500', prefix, 'test.hdf5'))
        val_dset = val_f['2dto3d']
        if debug_run:
            val_dta = np.array(val_dset[:10])
        else:
            val_dta = np.array(val_dset)
        preprocess(val_dta)
    train_annot = train_dta[:, 182 + rangestart:182 + rangeend]
    val_annot = val_dta[:, 182 + rangestart:182 + rangeend]
    rel_ids = create_featseltuple(lmset_to_use[(rangestart, rangeend)])
    train_dta = train_dta[:, rel_ids]
    val_dta = val_dta[:, rel_ids]
    if rangestart > 0 and rangestart < 82:
        train_annot = axis_angle_to_matrix(train_annot)
        val_annot = axis_angle_to_matrix(val_annot)
    return train_dta, train_annot, val_dta, val_annot
Exemplo n.º 2
0
 def test_matrix_cycle(self):
     """Test cycling from axis angle through matrix through versor back."""
     np.random.seed(1)
     angles = self._create_test_axis_angle_matrix()
     mat = conversions.axis_angle_to_matrix(angles)
     vers = conversions.matrix_to_versor(mat)
     angles_res = conversions.versor_to_axis_angle_ipr(vers)
     '''
     for idx in range(1000):
         if not np.allclose(angles[idx], angles_res[idx]):
             print(idx)
     '''
     self.assertTrue(np.allclose(angles, angles_res))
Exemplo n.º 3
0
 def test_multitarget(self):
     """Test multiple prediction target functionality."""
     #np.seterr(all='raise')
     angles = self._create_test_axis_angle_matrix(n_angles=2)
     mat = conversions.axis_angle_to_matrix(angles)
     dta = np.random.uniform(size=(1000, 5))
     from rotation_forest import RotationForest
     rf = RotationForest(n_jobs=2)  # pylint: disable=invalid-name
     rf.fit(dta, mat)
     res = rf.predict(dta)
     import cPickle as pickle
     pstr = pickle.dumps(rf)
     nf = pickle.loads(pstr)  # pylint: disable=invalid-name
     self.assertTrue(np.all(nf.predict(dta) == res))
Exemplo n.º 4
0
 def test_matrix_projection(self):
     """Test the manifold projection."""
     np.random.seed(1)
     angles = self._create_test_axis_angle_matrix()
     mat = conversions.axis_angle_to_matrix(angles)
     n_failed = 0
     for matrix_id, matrix in enumerate(mat):  # pylint: disable=unused-variable
         self.assertTrue(
             np.allclose(np.linalg.det(matrix.reshape((3, 3))), 1.))
         """
         if not np.allclose(np.dot(matrix.reshape((3, 3)),
                                   matrix.reshape((3, 3)).T),
                            np.eye(3), atol=1e-6):
             print np.dot(matrix.reshape((3, 3)), matrix.reshape((3, 3)).T), matrix_id
         """
         self.assertTrue(
             np.allclose(np.dot(matrix.reshape((3, 3)),
                                matrix.reshape((3, 3)).T),
                         np.eye(3),
                         atol=1e-6))
         # Perturb.
         offs = np.random.normal()
         idx = np.random.randint(low=0, high=9)
         matrix[idx] += offs
         # Recover.
         try:
             rec, dist = conversions.project_to_rot(matrix)  # pylint: disable=unused-variable
             self.assertTrue(
                 np.allclose(np.linalg.det(rec.reshape((3, 3))),
                             1.,
                             atol=1e-5))
             """
             if not np.allclose(np.dot(rec.reshape((3, 3)),
                                       rec.reshape((3, 3)).T),
                                np.eye(3), atol=1e-6):
                 print np.dot(rec.reshape((3, 3)),
                              rec.reshape((3, 3)).T), matrix_id
             """
             self.assertTrue(
                 np.allclose(np.dot(rec.reshape((3, 3)),
                                    rec.reshape((3, 3)).T),
                             np.eye(3),
                             atol=1e-6))
         except:  # pylint: disable=bare-except
             n_failed += 1
     self.assertEqual(n_failed, 56)
Exemplo n.º 5
0
 def test_opencv_rodrigues(self):
     """Test the manifold projection."""
     import cv2
     np.random.seed(1)
     angles = self._create_test_axis_angle_matrix()
     mat = conversions.axis_angle_to_matrix(angles)
     n_failed = 0
     for matrix_id, matrix in enumerate(mat):  # pylint: disable=unused-variable
         self.assertTrue(
             np.allclose(np.linalg.det(matrix.reshape((3, 3))), 1.))
         """
         if not np.allclose(np.dot(matrix.reshape((3, 3)),
                                   matrix.reshape((3, 3)).T),
                            np.eye(3), atol=1e-6):
             print np.dot(matrix.reshape((3, 3)), matrix.reshape((3, 3)).T), matrix_id
         """
         self.assertTrue(
             np.allclose(np.dot(matrix.reshape((3, 3)),
                                matrix.reshape((3, 3)).T),
                         np.eye(3),
                         atol=1e-6))
         # Perturb.
         offs = np.random.normal()
         idx = np.random.randint(low=0, high=9)
         matrix[idx] += offs
         # Recover.
         rec = cv2.Rodrigues(cv2.Rodrigues(matrix.reshape((3, 3)))[0])[0]  # pylint: disable=unused-variable
         self.assertTrue(
             np.allclose(np.linalg.det(rec.reshape((3, 3))), 1., atol=1e-5))
         """
         if not np.allclose(np.dot(rec.reshape((3, 3)),
         rec.reshape((3, 3)).T),
         np.eye(3), atol=1e-6):
         print np.dot(rec.reshape((3, 3)),
         rec.reshape((3, 3)).T), matrix_id
         """
         self.assertTrue(
             np.allclose(np.dot(rec.reshape((3, 3)),
                                rec.reshape((3, 3)).T),
                         np.eye(3),
                         atol=1e-6))