Example #1
0
def eval(model, gen, x, y):
    """Validation function. 
    
    Args:
      model: keras model. 
      gen: object, data generator. 
      x: 3darray, input, (n_segs, n_concat, n_freq)
      y: 2darray, target, (n_segs, n_freq)
    """
    pred_all, y_all = [], []

    # Inference in mini batch.
    for (batch_x, batch_y) in gen.generate(xs=[x], ys=[y]):
        pred = model.predict(batch_x)
        pred_all.append(pred)
        y_all.append(batch_y)
        if False:
            print("pred")
            print(pred)

    # Concatenate mini batch prediction.
    pred_all = np.concatenate(pred_all, axis=0)
    y_all = np.concatenate(y_all, axis=0)

    # Compute loss.
    loss = pp_data.np_mean_absolute_error(y_all, pred_all)
    return loss
Example #2
0
def eval(sess, model, gen, x, y):
    """Validation function. 
    
    Args:
      model: keras model. 
      gen: object, data generator. 
      x: 3darray, input, (n_segs, n_concat, n_freq)
      y: 2darray, target, (n_segs, n_freq)
    """
    pred_all, y_all = [], []

    # Inference in mini batch.
    for (batch_x, batch_y) in gen.generate(xs=[x], ys=[y]):
        pred = sess.run([model.enhanced_outputs],
                        feed_dict={model.x_noisy: batch_x})
        pred = np.reshape(pred, (-1, batch_y.shape[1]))
        pred_all.append(pred)
        # batch_y = np.reshape(batch_y,(-1, batch_y.shape[1]))
        y_all.append(batch_y)

    # Concatenate mini batch prediction.
    pred_all = np.concatenate(pred_all, axis=0)
    y_all = np.concatenate(y_all, axis=0)

    # Compute loss.
    loss = pp_data.np_mean_absolute_error(y_all, pred_all)
    return loss
Example #3
0
def eval(model, gen, x1, x2, y1, y2, name, utts):
    """Validation function. 
    
    Args:
      model: keras model. 
      gen: object, data generator. 
      x: 3darray, input, (n_segs, n_concat, n_freq)
      y: 2darray, target, (n_segs, n_freq)
    """
    pred_all, y_all = [], []

    # Inference in mini batch. 
    for (batch_x, batch_y) in gen.generate([x1, x2, name], [y1, y2], utts):
        pred = model.predict(batch_x)
        pred_all.append(np.hstack(pred))
        y_all.append(np.hstack(batch_y))

    # Concatenate mini batch prediction. 
    pred_all = np.concatenate(pred_all, axis=0)
    y_all = np.concatenate(y_all, axis=0)

    # Compute loss. 
    loss = pp_data.np_mean_absolute_error(y_all, pred_all)
    return loss