Exemplo n.º 1
0
// class constructor
PoolLayer::PoolLayer(ivec inshape, ConvNet* net) :
    Fshape({2, 2}),
    InShape(inshape),
    Excitations(inshape[0], inshape[1], inshape[2])
{   
    Stride   = 2;
    
    OutShape = outshape(InShape, Fshape, Stride, 0);
    Steps    = calcsteps(InShape, Fshape, Stride, 0);
    
    Activations(OutShape[0], OutShape[1], OutShape[2]);
    Errors(OutShape[0], OutShape[1], OutShape[2]);
    Brain = net;
}
Exemplo n.º 2
0
Shape ImgShapeToRoiFrame(     // return shape in ROI frame
    const Shape&  shape,      // in: shape in image frame
    const DetPar& detpar_roi, // in: detpar wrt the ROI
    const DetPar& detpar)     // in
{
    Shape outshape(ShiftShape(shape, detpar_roi.x - detpar.x,
                                     detpar_roi.y - detpar.y));
    if (Valid(detpar.rot) && detpar.rot)
    {
        const MAT rotmat = getRotationMatrix2D(cv::Point2f(float(detpar_roi.x),
                                               float(detpar_roi.y)),
                                               -detpar.rot,
                                               1.);
        TransformShapeInPlace(outshape, rotmat);
    }
    return outshape;
}
Exemplo n.º 3
0
const Shape ShapeMod::ConformShapeToMod_Pinned_(
    VEC&         b,           // io: eigvec weights from previous iters of ASM
    const Shape& shape,       // in: shape suggested by the descriptor models
    int          ilev,        // in: pyramid level (0 is full size)
    const Shape& pinnedshape) // in: pinned landmarks
const
{
    static const double MAX_DIST = 0.5;
    static const int    MAX_ITERS = 50;

    Shape outshape(shape.clone());
    double dist = FLT_MAX;
    for (int iter = 0; dist > MAX_DIST && iter < MAX_ITERS; iter++)
    {
        outshape = ConformShapeToMod_(b, outshape, ilev);
        dist = ForcePinnedPoints(outshape, pinnedshape);
    }
    return outshape;
}
Exemplo n.º 4
0
Shape RoiShapeToImgFrame(     // return shape in image frame
    const Shape&  shape,      // in: shape in roi frame
    const Image&  face_roi,   // in
    const DetPar& detpar_roi, // in: detpar wrt the ROI
    const DetPar& detpar)     // in: detpar wrt the image
{
    Shape outshape(shape.clone());
    if (IsLeftFacing(detpar.eyaw))
        outshape = FlipShape(outshape, face_roi.cols);
    if (Valid(detpar.rot) && detpar.rot)
    {
        const MAT rotmat =
            getRotationMatrix2D(cv::Point2f(float(detpar_roi.x),
                                            float(detpar_roi.y)),
                                detpar.rot, 1.);
        TransformShapeInPlace(outshape, rotmat);
    }
    return ShiftShape(outshape, detpar.x - detpar_roi.x,
                                detpar.y - detpar_roi.y);
}
Exemplo n.º 5
0
ConvLayer::ConvLayer(int filters, ivec inshape, ivec fshape, int stride,
                     ConvNet* net)
{
    InShape  = inshape;
    Stride   = stride;
    Fshape   = fshape;
    OutShape = outshape(InShape, Fshape, Stride, filters);
    Steps    = calcsteps(InShape, Fshape, Stride, filters);
            
    dmatrix3 refE(OutShape[0], dmatrix2(OutShape[1], dvec(OutShape[2], 0.0)));
    refE.swap(Excitations);
    dmatrix3 refA(OutShape[0], dmatrix2(OutShape[1], dvec(OutShape[2], 0.0)));
    refA.swap(Activations);
    dmatrix3 refErr(OutShape[0],dmatrix2(OutShape[1],dvec(OutShape[2], 0.0)));
    refErr.swap(Errors);
    dmatrix4 flt(filters,dmatrix3(InShape[0],
                 dmatrix2(Fshape[0],dvec(Fshape[1], 0.5))));
    flt.swap(Filters);
    
    Brain = net;
}
Exemplo n.º 6
0
void KLMultinomial<T>::setup_impl(const Variables &inputs,
                                  const Variables &outputs) {
  NBLA_CHECK(inputs[0]->shape() == inputs[1]->shape(), error_code::value,
             "Dimensions of inputs must match. "
             "inputs[0]: %s != inputs[1]: %s.",
             string_join(inputs[0]->shape(), string(", ")).c_str(),
             string_join(inputs[1]->shape(), string(", ")).c_str());

  Shape_t inshape = inputs[0]->shape();
  NBLA_CHECK(base_axis_ < inshape.size(), error_code::value,
             "base_axis must be less than ndim of inputs[0]. "
             "base_axis: %d >= ndim of inputs[0]: %d.",
             base_axis_, inshape.size());

  Shape_t outshape(base_axis_ + 1);
  for (int i = 0; i < base_axis_; i++) {
    outshape[i] = inshape[i];
  }
  outshape[base_axis_] = 1;

  outputs[0]->reshape(outshape, true);
}
Exemplo n.º 7
0
Shape FlipShape(           // flip shape horizontally
    const Shape& shape,    // in
    int          imgwidth) // in
{
    const LANDMARK_INFO* info;
    switch (shape.rows)
    {
    case 77: info = LANDMARK_INFO_TAB; break;
    default: Err("Do not know how to mirror a %d shape", shape.rows);
    }
    Shape outshape(shape.rows, 2);
    for (int i = 0; i < shape.rows; i++)
    {
        int partner = info[i].partner;

        if (partner == -1) // no partner e.g. tip of nose
            partner = i;

        FlipPoint(outshape, shape, partner, i, imgwidth);
    }
    return outshape;
}
Exemplo n.º 8
0
static Shape As5PointShape( // return a 5 point shape
    const Shape& pinned,    // in: pinned landmarks, canonical 5 points are best
    const Shape& meanshape) // in: used only if pinned landmarks are not canonical
{
    CV_Assert(pinned.rows    == stasm_NLANDMARKS);
    CV_Assert(meanshape.rows == stasm_NLANDMARKS);

    Shape newpinned(pinned);

    if (!HaveCanonical5Points(pinned))
    {
        // Not canonical 5 point pinned landmarks.  Impute the missing points.
        // This is not an optimal situation but will at least allow estimation
        // of pose from  an arb set of pinned landmarks.

        newpinned = PinMeanShape(pinned, meanshape);
    }

    Shape outshape(5, 2); // 5 point shape

    outshape(0, IX) = newpinned(L_LEyeOuter,    IX);
    outshape(0, IY) = newpinned(L_LEyeOuter,    IY);

    outshape(1, IX) = newpinned(L_REyeOuter,    IX);
    outshape(1, IY) = newpinned(L_REyeOuter,    IY);

    outshape(2, IX) = newpinned(L_CNoseTip,     IX);
    outshape(2, IY) = newpinned(L_CNoseTip,     IY);

    outshape(3, IX) = newpinned(L_LMouthCorner, IX);
    outshape(3, IY) = newpinned(L_LMouthCorner, IY);

    outshape(4, IX) = newpinned(L_RMouthCorner, IX);
    outshape(4, IY) = newpinned(L_RMouthCorner, IY);

    return outshape;
}