Example #1
0
void Pca::extract()
{
	Mat data = convVec(m_trainImages);
	int rows = data.rows;

	if (m_components <= 0 || m_components > rows)
		m_components = rows;

	PCA pca(data, Mat(), PCA::DATA_AS_ROW, int(m_components));

	m_data.clear();
	m_data.mean = pca.mean.clone().reshape(1, 1);
	m_data.eigenvalues = pca.eigenvalues.clone();
	transpose(pca.eigenvectors, m_data.eigenvectors);

	for (int i = 0; i < rows; i++) {
		Mat projected = pca.project(data.row(i).clone());
		m_data.train_projections.push_back(projected);
	}

	for (int i = 0; i < m_faces.size(); i++) {
		vector<Mat> projections;
		for (const auto &image : m_testImages[i]) {
			Mat projected = pca.project(convMat(image));
			projections.push_back(projected);
		}
		m_data.test_projections.push_back(projections);
	}

	m_data.labels = m_labels;
}
    void DeConvolutionLayer::forward(std::vector<Blob*> &inputs, std::vector<Blob> &outputs)
    {
        Blob &wghtBlob = blobs[0];

        for (size_t ii = 0; ii < outputs.size(); ii++)
        {
            Blob &convBlob = *inputs[ii];
            Blob &decnBlob = outputs[ii];

            for (int n = 0; n < convBlob.num(); n++)
            {
                for (int g = 0; g < group; g++)
                {
                    Mat dstMat(inpGroupCn, inpH*inpW, decnBlob.type(), decnBlob.ptr(n, g*inpGroupCn));

                    if (is1x1())
                        colMat = dstMat;

                    Mat convMat(outGroupCn, outH*outW, convBlob.type(), convBlob.ptr(n, g*outGroupCn));
                    Mat wghtMat(outGroupCn, ksize, wghtBlob.type(), wghtBlob.ptr(g*outGroupCn));
                    gemmCPU(wghtMat, convMat, 1, colMat, 0, GEMM_1_T);

                    col2im(dstMat);

                    if (bias)
                    {
                        float *biasPtr = blobs[1].ptrf() + g*inpGroupCn;
                        Mat biasMat(inpGroupCn, 1, CV_32F, biasPtr);
                        gemmCPU(biasMat, biasOnesMat, 1, dstMat, 1); //TODO: gemv
                    }
                }
            }
        }
    }
Example #3
0
void CAnm2D::renderOpenGL_FrameData(const FrameData &data, QMatrix4x4 mat)
{
	QRectF rect ;
	QRect uv = data.getRect() ;
	QRectF uvF ;

	AnmImage *pImage = getImage(data.nImage) ;
	if ( !pImage ) { return ; }

	const GLTexture *pTex = gEditData.getTexture(pImage->path) ;
	if ( !pTex ) { return ; }

	glPushMatrix() ;
	{
		double m[16] ;
		convMat(m, mat) ;
		m[14] /= 4096.0 ;
		glMultMatrixd(m) ;

		Vertex v = data.getVertex() ;
		rect.setLeft(v.x0);
		rect.setRight(v.x1) ;
		rect.setTop(v.y0);
		rect.setBottom(v.y1);

		int w = pTex->imgSize.width() ;
		int h = pTex->imgSize.height() ;
		uvF.setLeft((float)uv.left()/w) ;
		uvF.setRight((float)uv.right()/w) ;
		uvF.setTop(1.0f-(float)uv.top()/h) ;
		uvF.setBottom(1.0f-(float)uv.bottom()/h) ;

		glBindTexture(GL_TEXTURE_2D, pTex->nTexObj) ;

		QColor col ;
		col.setRed(data.rgba[0]);
		col.setGreen(data.rgba[1]);
		col.setBlue(data.rgba[2]);
		col.setAlpha(data.rgba[3]);

		drawRect(rect, uvF, 0, col) ;
	}
	glPopMatrix() ;
}