def test_epoch(self, dataset, trajectories_per_batch, nb_batchs=None):
        """ Test the model with an epoch of the dataset.
		"""
        self.model.eval()  # set the model in "testing mode"
        with torch.no_grad():
            loss_data = 0
            rmsae_data = 0

            n_trajectories = len(dataset)
            if nb_batchs is None:
                nb_batchs = n_trajectories // trajectories_per_batch

            for idx in range(nb_batchs):
                mic_sig_batch, acoustic_scene_batch = dataset.get_batch(
                    idx * trajectories_per_batch,
                    (idx + 1) * trajectories_per_batch)
                x_batch, DOA_batch = self.data_transformation(
                    mic_sig_batch, acoustic_scene_batch)
                DOA_batch_pred_cart = self.model(x_batch).contiguous()

                DOA_batch = DOA_batch.contiguous()
                DOA_batch_cart = sph2cart(DOA_batch)
                loss_data += torch.nn.functional.mse_loss(
                    DOA_batch_pred_cart.view(-1, 3),
                    DOA_batch_cart.view(-1, 3))

                DOA_batch_pred = cart2sph(DOA_batch_pred_cart)
                rmsae_data += rms_angular_error_deg(DOA_batch.view(-1, 2),
                                                    DOA_batch_pred.view(-1, 2))

            loss_data /= nb_batchs
            rmsae_data /= nb_batchs

            return loss_data, rmsae_data
Esempio n. 2
0
def azim_proj(pos):
    """
    Computes the Azimuthal Equidistant Projection of input point in 3D Cartesian Coordinates.
    Imagine a plane being placed against (tangent to) a globe. If
    a light source inside the globe projects the graticule onto
    the plane the result would be a planar, or azimuthal, map
    projection.
    :param pos: position in 3D Cartesian coordinates
    :return: projected coordinates using Azimuthal Equidistant Projection
    """
    [r, elev, az] = cart2sph(pos[0], pos[1], pos[2])
    return pol2cart(az, m.pi / 2 - elev)
def azim_proj(pos):
    """
    Computes the Azimuthal Equidistant Projection of input point in 3D Cartesian Coordinates.
    Imagine a plane being placed against (tangent to) a globe. If
    a light source inside the globe projects the graticule onto
    the plane the result would be a planar, or azimuthal, map
    projection.
    :param pos: position in 3D Cartesian coordinates
    :return: projected coordinates using Azimuthal Equidistant Projection
    """
    [r, elev, az] = cart2sph(pos[0], pos[1], pos[2])
    return pol2cart(az, m.pi / 2 - elev)
    def predict_batch(self, mic_sig_batch, vad_batch=None, return_x=False):
        """ Perform the model inference for an input batch.
		You can use return_x=True in order to return the input of the model in addition to the DOA estimation
		"""
        self.model.eval()  # set the model in "testing mode"

        n_trajectories = mic_sig_batch.shape[0]
        trajectory_len = mic_sig_batch.shape[1]

        x_batch = self.data_transformation(mic_sig_batch, vad_batch=vad_batch)

        DOA_batch_pred = self.model(x_batch).cpu().detach()

        DOA_batch_pred_cart = DOA_batch_pred.reshape(
            (n_trajectories, trajectory_len, 3))  # For split trajectories
        DOA_batch_pred = cart2sph(DOA_batch_pred_cart)

        if return_x:
            return DOA_batch_pred, x_batch.cpu().detach()
        else:
            return DOA_batch_pred
Esempio n. 5
0
def azim_proj(pos):

  [r, elev, az] = cart2sph(pos[0], pos[1], pos[2])
  return pol2cart(float(az), m.pi/2.0 - float(elev))