void testONNXModels(const String& basename, const Extension ext = npy,
                        const double l1 = 0, const float lInf = 0, const bool useSoftmax = false,
                        bool checkNoFallbacks = true)
    {
        String onnxmodel = _tf("models/" + basename + ".onnx");
        Mat inp, ref;
        if (ext == npy) {
            inp = blobFromNPY(_tf("data/input_" + basename + ".npy"));
            ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
        }
        else if (ext == pb) {
            inp = readTensorFromONNX(_tf("data/input_" + basename + ".pb"));
            ref = readTensorFromONNX(_tf("data/output_" + basename + ".pb"));
        }
        else
            CV_Error(Error::StsUnsupportedFormat, "Unsupported extension");

        checkBackend(&inp, &ref);
        Net net = readNetFromONNX(onnxmodel);
        ASSERT_FALSE(net.empty());

        net.setPreferableBackend(backend);
        net.setPreferableTarget(target);

        net.setInput(inp);
        Mat out = net.forward("");

        if (useSoftmax)
        {
            LayerParams lp;
            Net netSoftmax;
            netSoftmax.addLayerToPrev("softmaxLayer", "SoftMax", lp);
            netSoftmax.setPreferableBackend(DNN_BACKEND_OPENCV);

            netSoftmax.setInput(out);
            out = netSoftmax.forward();

            netSoftmax.setInput(ref);
            ref = netSoftmax.forward();
        }
        normAssert(ref, out, "", l1 ? l1 : default_l1, lInf ? lInf : default_lInf);
        if (checkNoFallbacks)
            expectNoFallbacksFromIE(net);
    }
int _tmain(int argc, _TCHAR* argv[])
{		
	int result = EXIT_SUCCESS;
	DOMConfigurator::configure("Log4cxxConfig.xml");
	string input;
	int playerPort;
	int destPort;
	int player = 0;
	Player playerA = Player();
	Player playerB = Player();

	char W[200]  = "W";
	char A[200]  = "A";
	char S[200]  = "S";
	char D[200]  = "D";

	network.initialise();
	//host or client for window title and for log.
	char* applicationName;

	applicationName = "Tag";

    SMALL_RECT windowSize = {0, 0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2};
    SetConsoleWindowInfo(hConsole, TRUE, &windowSize);
		
    
	bool gameOver = false;
	Vector2f mapBoundries = Vector2f(SCREEN_WIDTH, SCREEN_HEIGHT);
	
	
	
	RenderWindow renderWindow(VideoMode(SCREEN_WIDTH/2, SCREEN_HEIGHT, 32), applicationName);
	renderWindow.SetFramerateLimit(30);
	renderWindow.SetSize(SCREEN_WIDTH/2, SCREEN_HEIGHT);
	Shape player1circle = sf::Shape::Circle(Vector2f(0,0), 20.0f, sf::Color::Blue);
	Shape player2circle = sf::Shape::Circle(Vector2f(0,0), 20.0f, sf::Color::Red);



	cout << "Are you player A or B?";
	cin >> input;
	
	if (input == "a" || input == "A")
	{	

		player = 1;
		playerPort = 28000;
		destPort = 28001;
		playerA.setPort(playerPort);
		playerB.setPort(destPort);
		network.setupUDP(28000,_ip);
		LOG4CXX_INFO(loggerMyMain, "Player Binds A" );

	}

	else if (input == "b" || input == "B")
	{	
		
		player = 2;
		playerPort = 28001;
		destPort = 28000;
		playerA.setPort(destPort);
		playerB.setPort(playerPort);
		network.setupUDP(28001,_ip);
		LOG4CXX_INFO(loggerMyMain, "Player Binds B" );

	}

	playerA.setPosition(sf::Vector2f(80,80));
	playerB.setPosition(sf::Vector2f(120,120));

	player1circle.SetPosition(playerA.getPosition());
	player2circle.SetPosition(playerB.getPosition());

	try
	{

		//While the connection is not closed remotely
		while(renderWindow.IsOpened() && !gameOver)
		{		
		
			Event sfmlEvent;
		
			while (renderWindow.PollEvent(sfmlEvent))
			{
				// Close window : exit
				if (sfmlEvent.Type == Event::Closed)
				{
					renderWindow.Close();
				}
				else if (sfmlEvent.Type == Event::KeyPressed)
				{

				      if (sf::Keyboard::IsKeyPressed(sf::Keyboard::W))
					  {			
						if(player == 2)
						{
							playerA.update(1);
						}

						else if(player == 1)
						{
							playerB.update(1);
						}
						network.sendData("127.0.0.1",destPort, "W");
					  }

					  if (sf::Keyboard::IsKeyPressed(sf::Keyboard::A))
					  {			
						if(player == 2)
						{
							playerA.update(2);
						}

						else if(player == 1)
						{
							playerB.update(2);
						}
						network.sendData("127.0.0.1",destPort, "A");
					  }

					  if (sf::Keyboard::IsKeyPressed(sf::Keyboard::S))
					  {			
						if(player == 2)
						{
							playerA.update(3);
						}

						else if(player == 1)
						{
							playerB.update(3);
						}
						network.sendData("127.0.0.1",destPort, "S");
					  }

					  if (sf::Keyboard::IsKeyPressed(sf::Keyboard::D))
					  {			
						  if(player == 2)
						{
							playerA.update(4);
						}

						else if(player == 1)
						{
							playerB.update(4);
						}
						  network.sendData("127.0.0.1",destPort, "D");
					  }


					

					//cout << "Message recieved from, port = " << network.getSenderPort() << ", ip = "<< network.getSenderIP() << endl; 
					//messageRecieved = false;
					}

					if(network.receiveData(message))
					{
					LOG4CXX_INFO(loggerMyMain, message );
					
					if(strcmp(message , W) == 0)
					{		
						LOG4CXX_INFO(loggerMyMain, "Message Recieved" );
						LOG4CXX_INFO(loggerMyMain, message );
							if(player == 1)
							{
								playerA.update(1);
							}

							else if(player == 2)
							{
								playerB.update(1);
							}
					}

					if(strcmp(message , A) == 0)
					{
						LOG4CXX_INFO(loggerMyMain, "Message Recieved" );
						LOG4CXX_INFO(loggerMyMain, message );
							if(player == 1)
							{
								playerA.update(2);
							}

							else if(player == 2)
							{
								playerB.update(2);
							}				

					}

					if(strcmp(message , S) == 0)
					{
						LOG4CXX_INFO(loggerMyMain, "Message Recieved" );
						LOG4CXX_INFO(loggerMyMain, message );
							if(player == 1)
							{
								playerA.update(3);
							}

							else if(player == 2)
							{
								playerB.update(3);
							}
					}

					if(strcmp(message , D) == 0)
					{
						LOG4CXX_INFO(loggerMyMain, "Message Recieved" );
						LOG4CXX_INFO(loggerMyMain, message );
							if(player == 1)
							{
								playerA.update(4);
							}

							else if(player == 2)
							{
								playerB.update(4);
							}

						}


						  
					}
				}

				player1circle.SetPosition(playerA.getPosition());
				player2circle.SetPosition(playerB.getPosition());
			
				renderWindow.Clear();
				renderWindow.Draw(player1circle);
				renderWindow.Draw(player2circle);
				renderWindow.Display();
		}
	
		renderWindow.Close();
	
	

		cout << "Exiting application.\n";
    
	}
    catch(Exception&)
    {
		result = EXIT_FAILURE;
    }	

	
	return result;
}
Exemple #3
0
// Usage: caffe_('net_reshape', hNet)
static void net_reshape(MEX_ARGS) {
  mxCHECK(nrhs == 1 && mxIsStruct(prhs[0]),
      "Usage: caffe_('net_reshape', hNet)");
  Net<float>* net = handle_to_ptr<Net<float> >(prhs[0]);
  net->Reshape();
}
Exemple #4
0
// Usage: caffe_('net_backward', hNet)
static void net_backward(MEX_ARGS) {
  mxCHECK(nrhs == 1 && mxIsStruct(prhs[0]),
      "Usage: caffe_('net_backward', hNet)");
  Net<float>* net = handle_to_ptr<Net<float> >(prhs[0]);
  net->Backward();
}
TEST(Torch_Importer, simple_read)
{
    Net net;
    ASSERT_NO_THROW(net = readNetFromTorch(_tf("net_simple_net.txt"), false));
    ASSERT_FALSE(net.empty());
}
Exemple #6
0
int check_for_message(int sock) {
	static char * data=0;
	int message_length, sender;
	if(!data) data = new char[MAXMSGSIZE+1];
	MessageType type = get_message(sock, &data, message_length, &sender);
	if(type==NO_MESSAGE) return 0;
	//printf("organism recvd %i from %i\n", type, sender);
	if(type == SOUND) {
		char * msg = getStringFromData(data, message_length);
		//printf("%i) I hear sound %s length %i\n", myPort, msg, message_length);
		delete [] msg;
		if(sender!=myPort) { /*ignore sounds from myself*/
			myNet.feedInput(data, message_length, "ear");
			usleep(200);
			myNet.addClick();
			usleep(200);
			myGenome.transcribeGene("//encourage_auditory", 2, genome_file, portstr.str().c_str());
		}
	} else if(type == VISION) {
		//printf("start vision\n");
		if(message_length<=0) {
			organism_of_focus=worldPort;
			if(success(30)) {
				char data[2]={60,0};
				send_message(myPort, worldPort, TURN, 1, data);
				usleep(1600);
			}
		} else {
			memcpy(&organism_of_focus, data, sizeof(int));
			myNet.feedInput(data, message_length, "eye");
			char * dx_str = &data[sizeof(int)];
			float dx;
			memcpy(&dx, dx_str, sizeof(float));
			/*if(myPort==49153) {
				printf("%i at %g\n", organism_of_focus, dx);
			}*/
			if(dx<2.0) {
				if(std::find(children.begin(), children.end(), organism_of_focus) == children.end()) {
					stringstream destination_str;  destination_str<<organism_of_focus;
					myGenome.transcribeGene("//eat", 2, portstr.str().c_str(), destination_str.str().c_str());
				}
			}
			//printf("%i focus on %i dx %g\n", myPort, organism_of_focus, dx);
		}
		//printf("end vision\n");
	} else if(type == EAT) {
		int victim;
		memcpy(&victim, data, sizeof(int));
		if(victim==myPort) {
			/*printf("I'm being eaten\n");*/
		} else {
			myNet.reward("eat", 0.5);
		}
	} else if(type == KILL) {
		//printf("%i received kill message\n", myPort);
		exit(0);
	} else if(type == MATE) {
		if(sender == worldPort) { /*mate directive*/
			if(organism_of_focus==worldPort) { /*I can't see anybody, mate with self*/
				stringstream child_file;  child_file<<genome_file<<n_children;
				myGenome.transcribeGene("//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()) ;
			} else { /*transmit request to potential mate*/
				printf("%i) send mate request to %i\n", myPort, organism_of_focus);
				send_message(myPort, organism_of_focus, MATE, strlen(genome_file), genome_file);
			}
		} else { /*the message came from a potential mate*/
			char * mate_genome = getStringFromData(data, message_length);
			printf("%i) received mate request from %i (%s)\n", myPort, sender, mate_genome);
			stringstream child_file;  child_file<<genome_file<<n_children;
			myGenome.transcribeGene("//sexual_reproduction", 5, portstr.str().c_str(), genome_file, mate_genome, child_file.str().c_str(), worldportstr.str().c_str()) ;
		}
	} else if(type == NEW_ORGANISM) {
		int child_id;
		memcpy(&child_id, data, sizeof(int));
		children.push_back(child_id);
		n_children++;
	} else if(type == DISPLAY) {
		myNet.printStats(1);
	} else if(type == SAVE) {
		char * filename = getStringFromData(data, message_length);
		stringstream cmd;
		cmd<<"cp "<<genome_file<<" "<<filename;
		system(cmd.str().c_str());
	}
	return 1;
}
Exemple #7
0
int main (int argc, char * argv[]) {
	worldportstr << worldPort;
	if(argc<2) return 1;
	genome_file = argv[1];  if(!genome_file) return 1;
	myGenome.attachFile(genome_file);
	if(argc>2) myPort=atoi(argv[2]); 
	portstr << myPort;
	int sock = UDP_bind(myPort);
	//printf("my file is %s waiting on port %i\n", genome_file, myPort);

	myGenome.transcribeGene("//green_appearance", 1, portstr.str().c_str());

	srandom(100);
	stringstream net_file;  net_file<<genome_file<<"."<<myPort<<".net";
	myNet.name = net_file.str();
	myNet.saveToFile(net_file.str().c_str());
	myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_auditory", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_reproduction", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_movement", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//add_turn", 2, genome_file, portstr.str().c_str());
	myGenome.transcribeGene("//connect_subnets", 2, genome_file, portstr.str().c_str());
	myNet.loadFromFile(net_file.str().c_str());
	myNet.printStats();

	//printf("body\n");

	stringstream child_file;  child_file<<genome_file<<n_children;
	//myGenome.transcribeGene("//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str());
	
	int n=4;
	while(1) {
		try {
			int status; while (waitpid(-1, &status, WNOHANG)>0);

			int nMessages=0; do {
				nMessages = check_for_message(sock);
			} while (nMessages>0);

			myNet.addClick();

			map<string,int>output_length; map<string,unsigned char*>output_data;
			myNet.getOutput(output_length, output_data);

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "talk", 0.25, "//say", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "move", 0.2, "//move", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "turn", 0.1, "//turn", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "attack", 0.1, "//attack", 1, portstr.str().c_str()) ;

			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "eat", 0.2, "//eat", 1, portstr.str().c_str()) ;

			stringstream child_file;  child_file<<genome_file<<n_children;
			myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "reproduction", 0.33, "//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()) ;
	
			usleep(1000);
			//sleep(2);
		} 
		catch (...) {
			printf("organism %i error\n", myPort);
		}
	}
	close (sock);
	
	return 1;
}