void MulticlassEvaluator::evaluate(Learner& learner, DataSet& dataSet) { if(++iteration % interval == 0) { const int N = dataSet.samples(); double e = 0.0; int correct = 0; int wrong = 0; Eigen::VectorXd temporaryOutput(dataSet.outputs()); for(int n = 0; n < N; n++) { Eigen::VectorXd y = learner(dataSet.getInstance(n)); temporaryOutput = dataSet.getTarget(n); e += (y - temporaryOutput).squaredNorm(); int j1 = oneOfCDecoding(temporaryOutput); int j2 = oneOfCDecoding(y); if(j1 == j2) correct++; else wrong++; } e /= N; *logger << iteration << " " << e << " " << correct << " " << wrong << " " << stopwatch->stop(Stopwatch::MILLISECOND) << "\n"; } }
void transformsChain::runTransform( const ptr<image>& inputImage, std::uint32_t inputTopLeftX, std::uint32_t inputTopLeftY, std::uint32_t inputWidth, std::uint32_t inputHeight, const ptr<image>& outputImage, std::uint32_t outputTopLeftX, std::uint32_t outputTopLeftY) { if(isEmpty()) { ptr<transformHighBit> highBit(new transformHighBit); highBit->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, inputHeight, outputImage, outputTopLeftX, outputTopLeftY); return; } if(m_transformsList.size() == 1) { m_transformsList.front()->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, inputHeight, outputImage, outputTopLeftX, outputTopLeftY); return; } // Get the position of the last transform /////////////////////////////////////////////////////////// tTransformsList::iterator lastTransform(m_transformsList.end()); --lastTransform; std::wstring inputColorSpace(inputImage->getColorSpace()); image::bitDepth inputDepth(inputImage->getDepth()); std::uint32_t inputHighBit(inputImage->getHighBit()); std::wstring outputColorSpace(outputImage->getColorSpace()); image::bitDepth outputDepth(outputImage->getDepth()); std::uint32_t outputHighBit(outputImage->getHighBit()); std::uint32_t allocateRows = 65536 / inputWidth; if(allocateRows < 1) { allocateRows = 1; } if(allocateRows > inputHeight) { allocateRows = inputHeight; } // Allocate temporary images /////////////////////////////////////////////////////////// if( m_inputWidth != inputWidth || m_inputHeight != inputHeight || m_inputColorSpace != inputColorSpace || m_inputDepth != inputDepth || m_inputHighBit != inputHighBit || m_outputColorSpace != outputColorSpace || m_outputDepth != outputDepth || m_outputHighBit != outputHighBit) { m_inputWidth = inputWidth; m_inputHeight = inputHeight; m_inputColorSpace = inputColorSpace; m_inputDepth = inputDepth; m_inputHighBit = inputHighBit; m_outputColorSpace = outputColorSpace; m_outputDepth = outputDepth; m_outputHighBit = outputHighBit; m_temporaryImages.clear(); tTransformsList::iterator scanTransforms(m_transformsList.begin()); m_temporaryImages.push_back((*scanTransforms)->allocateOutputImage(inputImage, inputWidth, allocateRows)); while(++scanTransforms != lastTransform) { m_temporaryImages.push_back((*scanTransforms)->allocateOutputImage(m_temporaryImages.back(), inputWidth, allocateRows)); } } // Run all the transforms. Split the images into several // parts /////////////////////////////////////////////////////////// while(inputHeight != 0) { std::uint32_t rows = allocateRows; if(rows > inputHeight) { rows = inputHeight; } inputHeight -= rows; tTransformsList::iterator scanTransforms(m_transformsList.begin()); tTemporaryImagesList::iterator scanTemporaryImages(m_temporaryImages.begin()); (*scanTransforms)->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, rows, *scanTemporaryImages, 0, 0); inputTopLeftY += rows; while(++scanTransforms != lastTransform) { ptr<image> temporaryInput(*(scanTemporaryImages++)); ptr<image> temporaryOutput(*scanTemporaryImages); (*scanTransforms)->runTransform(temporaryInput, 0, 0, inputWidth, rows, temporaryOutput, 0, 0); } m_transformsList.back()->runTransform(*scanTemporaryImages, 0, 0, inputWidth, rows, outputImage, outputTopLeftX, outputTopLeftY); outputTopLeftY += rows; } }