예제 #1
0
int main(int argc, char** argv)
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	setRandSeed(12345679);
	if (argc != 2)
		exitWithUsageError();
	if (strcmp(argv[1], "-t") == 0)
	{
		std::cerr << "Testing basic graph activity.\n";
		testBasic();
		std::cerr << "Testing Tarjan`s algorithm.\n";
		testTarjan();
		std::cerr << "Testing 2-SAT solution.\n";
		test2SAT();
		return 0;
	}

	std::unique_ptr<IDigraph> graph = prepareInput(argv[1]);
	int variables = graph->getNumberOfVertices() / 2;
	std::vector<int> result = solve2SAT(graph, variables);
	if (result[0] == -1) std::cout << "No solution." << std::endl;
	else
	{
		std::cout << "Solution is:" << std::endl;
		for (int i = 0; i < variables; i++)
			std::cout << i + 1 << " -- " << (result[i] == 0 ? "false" : "true") << std::endl;
	}
	return 0;
}
예제 #2
0
void jpcnn_classify_image(void* networkHandle, void* inputHandle, unsigned int flags, int layerOffset, float** outPredictionsValues, int* outPredictionsLength, char*** outPredictionsNames, int* outPredictionsNamesLength) {

  const bool doMultiSample = (flags & JPCNN_MULTISAMPLE);
  const bool doRandomSample = (flags & JPCNN_RANDOM_SAMPLE);
  const bool skipRescale = (flags & JPCNN_SKIP_RESCALE);

  Graph* graph = (Graph*)(networkHandle);
  Buffer* input = (Buffer*)(inputHandle);

  bool doFlip;
  int imageSize;
  bool isMeanChanneled;
  if (graph->_isHomebrewed) {
    imageSize = 224;
    doFlip = false;
    isMeanChanneled = true;
  } else {
    imageSize = 227;
    doFlip = true;
    isMeanChanneled = false;
  }

  Buffer* rescaledInput;
  if (skipRescale) {
    // substract mean
    rescaledInput = new Buffer(Dimensions(input->_dims[0], graph->_inputSize, graph->_inputSize, 1));
    rescaledInput->copyDataFrom(input);
    matrix_add_inplace(rescaledInput, graph->_dataMean, -1.0f);
  } else {
    const int rescaledSize = graph->_inputSize;
    PrepareInput prepareInput(graph->_dataMean, !doMultiSample, doFlip, doRandomSample, imageSize, rescaledSize, isMeanChanneled);
    rescaledInput = prepareInput.run(input);
  }
  Buffer* predictions = graph->run(rescaledInput, layerOffset);


  *outPredictionsValues = predictions->_data;
  *outPredictionsLength = predictions->_dims.elementCount();
  if (layerOffset == 0) {
    *outPredictionsNames = graph->_labelNames;
    *outPredictionsNamesLength = graph->_labelNamesLength;
  } else {
    *outPredictionsNames = NULL;
    *outPredictionsNamesLength = predictions->_dims.removeDimensions(1).elementCount();
  }
}