예제 #1
0
bool CommunicationLayer::sendToLayer(
	Directions direction, PacketPtr packet, t_uint recvingLayerIdx)
{
	assert(packet != 0);
	assert(recvingLayerIdx < numberOfLayers(direction));
	CommunicationLayerPtr recvingLayer;
	switch(direction) {
	case Directions_Lower:
		recvingLayer = m_lowerLayers[recvingLayerIdx];
		break;
	case Directions_Upper:
		removeLayerData(packet);
		recvingLayer = m_upperLayers[recvingLayerIdx];
		break;
	default:
		assert(false);
	}
	assert(recvingLayer.get() != 0);

	LogStreamManager::instance()->logPktSendItem(getNodeId(),
		getLayerType(), *packet);
	EventPtr recvEvent = LayerRecvEvent::create(direction, 
		packet, recvingLayer, shared_from_this());

	if(direction == Directions_Lower)
		setLowerLayerRecvEventPending(true);

	assert(m_node != 0);
	bool wasScheduled = m_node->scheduleEvent(recvEvent, 
		getLayerDelay(direction));
	return wasScheduled;
}
예제 #2
0
	string BNLLLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + mName         + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}


		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
void ConstructionObjectVectorController::onDrop(const OSItemId& itemId)
{
  if(m_modelObject){
    boost::optional<model::Material> material = this->addToModel<model::Material>(itemId);
    if(!material) return;
    
    model::LayeredConstruction construction = m_modelObject->cast<model::LayeredConstruction>();
    std::vector<model::Material> layers =  construction.layers();
    if(layers.size()){

      IddObjectType existingIddObjectType = layers.at(0).iddObjectType();
      IddObjectType newIddObjectType = material.get().iddObjectType();

      LayerType existingLayerType = getLayerType(existingIddObjectType);
      LayerType newLayerType = getLayerType(newIddObjectType);

      // Need a valid widget to hang the msgbox on
      OS_ASSERT(this->parentWidget());

      if(existingLayerType == ConstructionObjectVectorController::AIRWALL){
        // Only 1 layer allowed for AirWall
        QMessageBox::warning(this->parentWidget(), 
          "Error Adding Layer",
          "Only 1 layer allowed for an AirWall.",
          QMessageBox::Ok);
        return;
      }
      else if(newLayerType != existingLayerType){
        // New layer type must match existing layer type
        QMessageBox::warning(this->parentWidget(), 
          "Error Adding Layer",
          "New layer type must match existing layer type.",
          QMessageBox::Ok);
        return;
      }
    }
    construction.insertLayer(construction.numLayers(),*material);
  }
}
예제 #4
0
파일: layergl.cpp 프로젝트: Ojaswi/inviwo
LayerGL::LayerGL(size2_t dimensions, LayerType type, const DataFormatBase* format, std::shared_ptr<Texture2D> tex)
    : LayerRepresentation(dimensions, type, format), texture_(tex) {
    if (!texture_) {
        GLFormats::GLFormat glFormat = getGLFormats()->getGLFormat(getDataFormatId());

        if (getLayerType() == LayerType::Depth) {
            texture_ = std::make_shared<Texture2D>(getDimensions(), GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24,
                glFormat.type, GL_NEAREST);
        } else {
            texture_ = std::make_shared<Texture2D>(getDimensions(), glFormat, GL_LINEAR);
        }
    }
}
예제 #5
0
bool Layer::isEquals(const Layer* that) const {
  if (this == that) {
    return true;
  }

  if (that == NULL) {
    return false;
  }

  if (getLayerType() != that->getLayerType()) {
    return false;
  }

  if (_condition != that->_condition) {
    return false;
  }

  const int thisListenersSize = _listeners.size();
  const int thatListenersSize = that->_listeners.size();
  if (thisListenersSize != thatListenersSize) {
    return false;
  }

  for (int i = 0; i < thisListenersSize; i++) {
    if (_listeners[i] != that->_listeners[i]) {
      return false;
    }
  }

  if (_enable != that->_enable) {
    return false;
  }

  if (!(_name == that->_name)) {
    return false;
  }

  if (!_parameters->isEquals(that->_parameters)) {
    return false;
  }

  if (_timeToCacheMS != that->_timeToCacheMS) {
    return false;
  }

  if (_readExpired != that->_readExpired) {
    return false;
  }

  return rawIsEquals(that);
}
예제 #6
0
BOOST_AUTO_TEST_CASE_TEMPLATE(factory, T, float_types)
{
	auto input = createLayer<T>(10, "input");
	auto output = createLayer<T>(10, "output");
	auto fc = createLayer<T>(7, 10, "fc");
	auto nl = createLayer<T>(9, "nl tanh");
	
	// check results
	BOOST_CHECK_EQUAL( input->getNumNeurons(), 10 );
	BOOST_CHECK_EQUAL( input->getNumInputs(), 0 );
	BOOST_CHECK_EQUAL( input->getLayerType(), "input" );
	
	BOOST_CHECK_EQUAL( output->getNumNeurons(), 10 );
	BOOST_CHECK_EQUAL( output->getNumInputs(), 10 );
	BOOST_CHECK_EQUAL( output->getLayerType(), "output" );
	
	BOOST_CHECK_EQUAL( fc->getNumNeurons(), 10 );
	BOOST_CHECK_EQUAL( fc->getNumInputs(), 7 );
	BOOST_CHECK_EQUAL( fc->getLayerType(), "fc" );
	
	BOOST_CHECK_EQUAL( nl->getNumNeurons(), 9 );
	BOOST_CHECK_EQUAL( nl->getNumInputs(), 9 );
	BOOST_CHECK_EQUAL( nl->getLayerType(), "nl" );
}
예제 #7
0
void CommunicationLayer::removeLayerData(PacketPtr packet) const
{
	switch(getLayerType()) {
	case Types_Application:
		packet->removeData(Packet::DataTypes_Application);
		break;
	case Types_Transport:
		packet->removeData(Packet::DataTypes_Transport);
		break;
	case Types_Network:
		packet->removeData(Packet::DataTypes_Network);
		break;
	case Types_Link:
		packet->removeData(Packet::DataTypes_Link);
		break;
	case Types_Physical:
		packet->removeData(Packet::DataTypes_Physical);
		break;
	default:
		assert(false);
	}
}
예제 #8
0
bool CommunicationLayer::recvFromLayer(Directions direction, 
	PacketPtr packet, CommunicationLayerPtr sendingLayer)
{
	bool layerFound = false;
	t_uint sendingLayerIdx;

	vector<CommunicationLayerPtr>* layerVector = 0;
	switch(direction) {
	case Directions_Lower:
		layerVector = &m_lowerLayers;
		break;
	case Directions_Upper:
		layerVector = &m_upperLayers;
		break;
	default:
		assert(false);
	}
	assert(layerVector != 0);

	t_uint layersTotal = numberOfLayers(direction);
	for(t_uint i = 0; i < layersTotal; i++) {
		if((*layerVector)[i] == sendingLayer) {
			layerFound = true;
			sendingLayerIdx = i;
			break;
		}
	}

	bool wasRecvd = false;
	if(layerFound) {
		LogStreamManager::instance()->logPktRecvItem(getNodeId(),
			getLayerType(), *packet);
		wasRecvd = recvFromLayer(direction, packet, sendingLayerIdx);
	}
	return wasRecvd;
}
예제 #9
0
	string SoftmaxLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string SoftmaxParamStrStart = "\tsoftmax_param\n\t{\n";
		string SoftmaxParamStrEnd = "\t}\n";

                string engineStrStart = "\t\tengine: ";
		string engineStrEnd = "\n";

		string axisStrStart = "\t\taxis: ";
		string axisStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + mName         + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + 
			     SoftmaxParamStrStart ;

		if(((SoftmaxParam*)mParam)->mEngine != MMALab::DEFAULT)
		{
			switch (((SoftmaxParam*)mParam)->mEngine)
			{			
			case MMALab::CAFFE:
				outStr += engineStrStart+ "CAFFE" + engineStrEnd;			
				break;
			case MMALab::CUDNN:
				outStr += engineStrStart+ "CUDNN" + engineStrEnd;
			}
		}
                if(((SoftmaxParam*)mParam)->mAxis != 1)
		{
			outStr += axisStrStart + to_string(getAxis()) + axisStrEnd;
		}

		outStr += SoftmaxParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #10
0
	string ConcatLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string concatParamStrStart = "\tconcat_param\n\t{\n";
		string concatParamStrEnd = "\t}\n";

		string axisStrStart = "\t\taxis: ";
		string axisStrEnd = "\n";

		string concatDimStrStart = "\t\tconcat_dim: ";
		string concatDimStrEnd = "\n";

		string ignorelabelStrStart = "\t\tignore_label: ";
		string ignorelabelStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + getLayerName()    + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + 
			     concatParamStrStart ;
		if(((ConcatParam*)mParam)->mAxis != 1)
		{
			outStr +=  axisStrStart + to_string(getAxis()) + axisStrEnd;
		}

		if(((ConcatParam*)mParam)->mConcatDim != -1)
		{
			outStr += concatDimStrStart + to_string(getConcatDim()) + concatDimStrEnd;
		}				 
		outStr += concatParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #11
0
	string SigmoidLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string sigmoidParamStrStart = "\tsigmoid_param\n\t{\n";
		string sigmoidParamStrEnd = "\t}\n";

		string engineStrStart = "\t\tengine: ";
		string engineStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + mName         + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + sigmoidParamStrStart;

		if (getEngine() != MMALab::DEFAULT)
		{
			switch (getEngine())
			{
			case MMALab::CAFFE:
				outStr += engineStrStart + "CAFFE" + engineStrEnd;
				break;

			case MMALab::CUDNN:
				outStr += engineStrStart + "CUDNN" + engineStrEnd;
				break;
			}
		}				 

		outStr += sigmoidParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #12
0
	string PowerLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string powerParamStrStart = "\tpower_param\n\t{\n";
		string powerParamStrEnd = "\t}\n";

		string powerStrStart = "\t\tpower: ";
		string powerStrEnd = "\n";

		string scaleStrStart = "\t\tscale: ";
		string scaleStrEnd = "\n";

		string shiftStrStart = "\t\tshift: ";
		string shiftStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + mName         + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + powerParamStrStart;

		if (getPower() != 1.0)
		{
			outStr += powerStrStart + to_string(getPower()) + powerStrEnd;
		}

		if (getScale() != 1.0)
		{
			outStr += scaleStrStart + to_string(getScale()) + scaleStrEnd;
		}

		if (getShift() != 0.0)
		{
			outStr += shiftStrStart + to_string(getShift()) + shiftStrEnd;
		}
				 
		outStr += powerParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #13
0
bool TileSupervisor::Load(ReadScriptDescriptor& map_file) {
	// Load the map dimensions and do some basic sanity checks
	_num_tile_on_y_axis = map_file.ReadInt("num_tile_rows");
	_num_tile_on_x_axis = map_file.ReadInt("num_tile_cols");

	std::vector<int32> context_inherits;
	//map_file.ReadUIntVector("context_inherits", context_inherits);
	map_file.OpenTable("contexts");
	uint32 num_contexts = map_file.GetTableSize();
	for (uint32 context_id = 0;  context_id < num_contexts; ++context_id) {
		map_file.OpenTable(context_id);
		int32 inheritance = map_file.ReadInt("inherit_from");

		// The base context can't inherit from another one
		if (context_id == 0)
			inheritance = -1;

		// A context can't inherit from a context with a higher id, or itself.
		if ((int32)context_id <= inheritance || inheritance < -1)
			inheritance = -1;

		context_inherits.push_back(inheritance);

		map_file.CloseTable();
	}
	map_file.CloseTable(); // contexts

	// Load all of the tileset images that are used by this map

	// Contains all of the tileset filenames used (string does not contain path information or file extensions)
	std::vector<std::string> tileset_filenames;
	// Temporarily retains all tile images loaded for each tileset. Each inner vector contains 256 StillImage objects
	std::vector<std::vector<StillImage> > tileset_images;

	map_file.ReadStringVector("tileset_filenames", tileset_filenames);

	for (uint32 i = 0; i < tileset_filenames.size(); i++) {
		// Construct the image filename from the tileset filename and create a new vector to use in the LoadMultiImage call
		std::string image_filename = "img/tilesets/" + tileset_filenames[i] + ".png";
		tileset_images.push_back(std::vector<StillImage>(TILES_PER_TILESET));

		// Each tileset image is 512x512 pixels, yielding 16 * 16 (== 256) 32x32 pixel tiles each
		if (!ImageDescriptor::LoadMultiImageFromElementGrid(tileset_images[i], image_filename, 16, 16)) {
			PRINT_ERROR << "failed to load tileset image: " << image_filename << std::endl;
			return false;
		}

		// The map mode coordinate system used corresponds to a tile size of (2.0, 2.0)
		for (uint32 j = 0; j < TILES_PER_TILESET; j++) {
			tileset_images[i][j].SetDimensions(2.0f, 2.0f);
			tileset_images[i][j].Smooth(VideoManager->ShouldSmoothPixelArt());
		}
	}

	if (!map_file.DoesTableExist("layers")) {
		PRINT_ERROR << "No 'layers' table in the map file." << std::endl;
		return false;
	}

	// Read in the map tile indeces from all tile layers for the base context
	// The indeces stored for the map layers in this file directly correspond to a location within a tileset. Tilesets contain a total of 256 tiles
	// each, so 0-255 correspond to the first tileset, 256-511 the second, etc. The tile location within the tileset is also determined by the index,
	// where the first 16 indeces in the tileset range are the tiles of the first row (left to right), and so on.

	// Create the base context
	_tile_grid.clear();
	_tile_grid.insert(std::make_pair(MAP_CONTEXT_01, Context()));

	std::vector<int32> table_x_indeces; // Used to temporarily store a row of table indeces

	map_file.OpenTable("layers");

	uint32 layers_number = map_file.GetTableSize();

	// layers[0]-[n]
	for (uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
		// Opens the sub-table: layers[layer_id]
		if (!map_file.DoesTableExist(layer_id))
			continue;

		map_file.OpenTable(layer_id);

		// Add a layer for the base context
		_tile_grid[MAP_CONTEXT_01].resize(layer_id + 1);

		LAYER_TYPE layer_type = getLayerType(map_file.ReadString("type"));

		if (layer_type == INVALID_LAYER) {
			PRINT_WARNING << "Ignoring unexisting layer type: " << layer_type
				<< " in file: " << map_file.GetFilename() << std::endl;
			map_file.CloseTable(); // layers[i]
			continue;
		}

		_tile_grid[MAP_CONTEXT_01][layer_id].layer_type = layer_type;

		// Add the new tile rows (y axis)
		_tile_grid[MAP_CONTEXT_01][layer_id].tiles.resize(_num_tile_on_y_axis);

		// Read the tile data
		for (uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
			table_x_indeces.clear();

			// Check to make sure tables are of the proper size
			if (!map_file.DoesTableExist(y)) {
				PRINT_ERROR << "the layers["<< layer_id <<"] table size was not equal to the number of tile rows specified by the map, "
					" first missing row: " << y << std::endl;
				return false;
			}

			map_file.ReadIntVector(y, table_x_indeces);

			// Check the number of columns
			if (table_x_indeces.size() != _num_tile_on_x_axis){
				PRINT_ERROR << "the layers[" << layer_id << "]["<< y << "] table size was not equal to the number of tile columns specified by the map, "
				"should have " << _num_tile_on_x_axis << " values."<< std::endl;
				return false;
			}

			// Prepare the columns (x axis)
			_tile_grid[MAP_CONTEXT_01][layer_id].tiles[y].resize(_num_tile_on_x_axis);

			for (uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
				_tile_grid[MAP_CONTEXT_01][layer_id].tiles[y][x] = table_x_indeces[x];
			}
		}
		map_file.CloseTable(); // layers[layer_id]
	}

	map_file.CloseTable(); // layers

	// Create each additional context for the map by loading its table data

	// Load the tile data for each additional map context
	for (uint32 ctxt = 1; ctxt < num_contexts; ++ctxt) {
		MAP_CONTEXT this_context = static_cast<MAP_CONTEXT>(1 << ctxt);
		std::string context_name = "context_";
		if (ctxt < 10) // precede single digit context names with a zero
			context_name += "0";
		context_name += NumberToString(ctxt);

		// Check wether the context inhjeritance id is lower than the current one.
		if (context_inherits[ctxt] >= (int32)ctxt) {
			PRINT_WARNING << "Invalid context inheritance found for context id: " << ctxt
			<< ". Permitted values goes from -1 (none) to " << ctxt - 1 << std::endl;
			continue;
		}

		// Initialize this context by making a copy of the base map context first, as most contexts re-use many of the same tiles from the base context
		// If non-inheriting context, start with empty map!
		if (context_inherits[ctxt] > -1) {
			_tile_grid.insert(std::make_pair(this_context,
										_tile_grid[GetContextMaskFromContextId(context_inherits[ctxt])]));
		}
		else {
			_tile_grid.insert(std::make_pair(this_context, Context()));

			// Resize the context to have the same size as the base one
			// The number of layers
			_tile_grid[this_context].resize(layers_number);
			// Fro each layer, set up the grid size
			for (uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
				// Type
				_tile_grid[this_context][layer_id].layer_type = _tile_grid[MAP_CONTEXT_01][layer_id].layer_type;
				// Height
				_tile_grid[this_context][layer_id].tiles.resize(_num_tile_on_y_axis);
				for (uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
					// and width
					_tile_grid[this_context][layer_id].tiles[y].assign((size_t)_num_tile_on_x_axis, -1);
				}
			}
		}

		// Read the table corresponding to this context and modify each tile accordingly.
		// The context table is an array of integer data. The size of this array should be divisible by four, as every consecutive group of four integers in
		// this table represent one tile context element. The first integer corresponds to the tile layer (0 = lower, 1 = middle, 2 = upper), the second
		// and third represent the row and column of the tile respectively, and the fourth value indicates which tile image should be used for this context.
		// So if the first four entries in the context table were {0, 12, 26, 180}, this would set the lower layer tile at position (12, 26) to the tile
		// index 180.
		std::vector<int32> context_data;
		map_file.ReadIntVector(context_name, context_data);
		if (context_data.size() % 4 != 0) {
			PRINT_WARNING <<  ", context data was not evenly divisible by four (incomplete context data)"
				<< " in context: " << this_context << std::endl;
			continue;
		}

		for (uint32 j = 0; j < context_data.size(); j += 4) {
			int32 layer_id = context_data[j];
			int32 y = context_data[j + 1];
			int32 x = context_data[j + 2];
			int32 tile_id = context_data[j + 3];

			if (y >= _num_tile_on_y_axis ||
					x >= _num_tile_on_x_axis ||
					layer_id >= (int32)_tile_grid[this_context].size()) {
				PRINT_WARNING << "Invalid context data found for context: " << this_context << ": layer id: " << layer_id
					<< ", x: " << x << ", y: " << y << std::endl;
				continue;
			}

			_tile_grid[this_context][layer_id].tiles[y][x] = tile_id;
		}
	} // for (uint32 ctxt = 1; ctxt < map_instance->_num_map_contexts; ++ctxt)


	// Determine which tiles in each tileset are referenced in this map

	// Used to determine whether each tile is used by the map or not. An entry of -1 indicates that particular tile is not used
	std::vector<int16> tile_references;
	// Set size to be equal to the total number of tiles and initialize all entries to -1 (unreferenced)
	tile_references.assign(tileset_filenames.size() * TILES_PER_TILESET, -1);

	std::map<MAP_CONTEXT, Context>::const_iterator it = _tile_grid.begin();
	std::map<MAP_CONTEXT, Context>::const_iterator it_end = _tile_grid.end();
	// For each context
	for (; it != it_end; ++it) {
		// For each layer
		for (uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
			// For each tile id
			for (uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
				for (uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
					if ((it->second)[layer_id].tiles[y][x] >= 0)
						tile_references[ (it->second)[layer_id].tiles[y][x] ] = 0;
				}
			}
		}
	}

	// Translate the tileset tile indeces into indeces for the vector of tile images

	// Here, we have to convert the original tile indeces defined in the map file into a new form. The original index
	// indicates the tileset where the tile is used and its location in that tileset. We need to convert those indeces
	// so that they serve as an index to the MapMode::_tile_images vector, where the tile images will soon be stored.

	// Keeps track of the next translated index number to assign
	uint32 next_index = 0;

	for (uint32 i = 0; i < tile_references.size(); ++i) {
		if (tile_references[i] >= 0) {
			tile_references[i] = next_index;
			next_index++;
		}
	}

	// Now, go back and re-assign all tile layer indeces with the translated indeces
	std::map<MAP_CONTEXT, Context>::iterator it2 = _tile_grid.begin();
	std::map<MAP_CONTEXT, Context>::iterator it2_end = _tile_grid.end();
	// For each context
	for (; it2 != it2_end; ++it2) {
		// For each layer
		for (uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
			// For each tile id
			for (uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
				for (uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
					if ((it2->second)[layer_id].tiles[y][x] >= 0)
						(it2->second)[layer_id].tiles[y][x] = tile_references[ (it2->second)[layer_id].tiles[y][x] ];
				}
			}
		}
	}

	// Parse all of the tileset definition files and create any animated tile images that will be used

	// Used to access the tileset definition file
	ReadScriptDescriptor tileset_script;
	// Temporarily retains the animation data (every two elements corresponds to a pair of tile frame index and display time)
	std::vector<uint32> animation_info;
	// Temporarily holds all animated tile images. The map key is the value of the tile index, before reference translation is done in the next step
	std::map<uint32, AnimatedImage*> tile_animations;

	for (uint32 i = 0; i < tileset_filenames.size(); i++) {
		if (tileset_script.OpenFile("dat/tilesets/" + tileset_filenames[i] + ".lua") == false) {
			PRINT_ERROR << "map failed to load because it could not open a tileset definition file: " << tileset_script.GetFilename() << std::endl;
			exit(1);
		}
		tileset_script.OpenTable(tileset_filenames[i]);

		if (tileset_script.DoesTableExist("animated_tiles") == true) {
			tileset_script.OpenTable("animated_tiles");
			for (uint32 j = 1; j <= tileset_script.GetTableSize(); j++) {
				animation_info.clear();
				tileset_script.ReadUIntVector(j, animation_info);

				// The index of the first frame in the animation. (i * TILES_PER_TILESET) factors in which tileset the frame comes from
				uint32 first_frame_index = animation_info[0] + (i * TILES_PER_TILESET);

				// If the first tile frame index of this animation was not referenced anywhere in the map, then the animation is unused and
				// we can safely skip over it and move on to the next one. Otherwise if it is referenced, we have to construct the animated image
				if (tile_references[first_frame_index] == -1) {
					continue;
				}

				AnimatedImage* new_animation = new AnimatedImage();
				new_animation->SetDimensions(2.0f, 2.0f);

				// Each pair of entries in the animation info indicate the tile frame index (k) and the time (k+1)
				for (uint32 k = 0; k < animation_info.size(); k += 2) {
					new_animation->AddFrame(tileset_images[i][animation_info[k]], animation_info[k+1]);
				}
				tile_animations.insert(std::make_pair(first_frame_index, new_animation));
			}
			tileset_script.CloseTable();
		}

		tileset_script.CloseTable();
		tileset_script.CloseFile();
	} // for (uint32 i = 0; i < tileset_filenames.size(); i++)

	// Add all referenced tiles to the _tile_images vector, in the proper order

	for (uint32 i = 0; i < tileset_images.size(); i++) {
		for (uint32 j = 0; j < TILES_PER_TILESET; j++) {
			uint32 reference = (i * TILES_PER_TILESET) + j;

			if (tile_references[reference] >= 0) {
				// Add the tile as a StillImage
				if (tile_animations.find(reference) == tile_animations.end()) {
					_tile_images.push_back(new StillImage(tileset_images[i][j]));
				}

				// Add the tile as an AnimatedImage
				else {
					_tile_images.push_back(tile_animations[reference]);
					_animated_tile_images.push_back(tile_animations[reference]);
					tile_animations.erase(reference);
				}
			}
		}
	}

	if (tile_animations.empty() == false) {
		IF_PRINT_WARNING(MAP_DEBUG) << "one or more tile animations that were created were not added into the map -- this is a memory leak" << std::endl;
	}

	// Remove all tileset images. Any tiles which were not added to _tile_images will no longer exist in memory
	tileset_images.clear();

	return true;
} // bool TileSupervisor::Load(ReadScriptDescriptor& map_file)
예제 #14
0
bool TileSupervisor::Load(ReadScriptDescriptor &map_file)
{
    // Load the map dimensions and do some basic sanity checks
    _num_tile_on_y_axis = map_file.ReadInt("num_tile_rows");
    _num_tile_on_x_axis = map_file.ReadInt("num_tile_cols");

    // Load all of the tileset images that are used by this map

    // Contains all of the tileset filenames used (string does not contain path information or file extensions)
    std::vector<std::string> tileset_filenames;
    // Temporarily retains all tile images loaded for each tileset. Each inner vector contains 256 StillImage objects
    std::vector<std::vector<StillImage> > tileset_images;

    map_file.ReadStringVector("tileset_filenames", tileset_filenames);

    for(uint32 i = 0; i < tileset_filenames.size(); i++) {
        std::string tileset_file = tileset_filenames[i];

        ReadScriptDescriptor tileset_script;
        if (!tileset_script.OpenFile(tileset_file)) {
            PRINT_ERROR << "Couldn't open the tileset definition file: " << tileset_file << std::endl;
            return false;
        }

        if (!tileset_script.OpenTable("tileset")) {
            PRINT_ERROR << "Couldn't open the 'tileset' table from file: " << tileset_file << std::endl;
            tileset_script.CloseFile();
            return false;
        }

        std::string image_filename = tileset_script.ReadString("image");
        tileset_script.CloseFile();

        tileset_images.push_back(std::vector<StillImage>(TILES_PER_TILESET));

        // Each tileset image is 512x512 pixels, yielding 16 * 16 (== 256) 32x32 pixel tiles each
        if(!ImageDescriptor::LoadMultiImageFromElementGrid(tileset_images[i], image_filename, 16, 16)) {
            PRINT_ERROR << "failed to load tileset image: " << image_filename << std::endl;
            return false;
        }

        // The map mode coordinate system used corresponds to a tile size of (2.0, 2.0)
        for(uint32 j = 0; j < TILES_PER_TILESET; j++) {
            tileset_images[i][j].SetDimensions(2.0f, 2.0f);
            tileset_images[i][j].Smooth(VideoManager->ShouldSmoothPixelArt());
        }
    }

    if(!map_file.DoesTableExist("layers")) {
        PRINT_ERROR << "No 'layers' table in the map file." << std::endl;
        return false;
    }

    // Read in the map tile indeces from all tile layers.
    // The indeces stored for the map layers in this file directly correspond to a location within a tileset. Tilesets contain a total of 256 tiles
    // each, so 0-255 correspond to the first tileset, 256-511 the second, etc. The tile location within the tileset is also determined by the index,
    // where the first 16 indeces in the tileset range are the tiles of the first row (left to right), and so on.

    // Clears out the tiles grid
    _tile_grid.clear();

    std::vector<int32> table_x_indeces; // Used to temporarily store a row of table indeces

    map_file.OpenTable("layers");

    uint32 layers_number = map_file.GetTableSize();

    // layers[0]-[n]
    for(uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
        // Opens the sub-table: layers[layer_id]
        if(!map_file.DoesTableExist(layer_id))
            continue;

        map_file.OpenTable(layer_id);

        // Add a layer for the base context
        _tile_grid.resize(layer_id + 1);

        LAYER_TYPE layer_type = getLayerType(map_file.ReadString("type"));

        if(layer_type == INVALID_LAYER) {
            PRINT_WARNING << "Ignoring unexisting layer type: " << layer_type
                          << " in file: " << map_file.GetFilename() << std::endl;
            map_file.CloseTable(); // layers[i]
            continue;
        }

        _tile_grid[layer_id].layer_type = layer_type;

        // Add the new tile rows (y axis)
        _tile_grid[layer_id].tiles.resize(_num_tile_on_y_axis);

        // Read the tile data
        for(uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
            table_x_indeces.clear();

            // Check to make sure tables are of the proper size
            if(!map_file.DoesTableExist(y)) {
                PRINT_ERROR << "the layers[" << layer_id << "] table size was not equal to the number of tile rows specified by the map, "
                            " first missing row: " << y << std::endl;
                return false;
            }

            map_file.ReadIntVector(y, table_x_indeces);

            // Check the number of columns
            if(table_x_indeces.size() != _num_tile_on_x_axis) {
                PRINT_ERROR << "the layers[" << layer_id << "][" << y << "] table size was not equal to the number of tile columns specified by the map, "
                            "should have " << _num_tile_on_x_axis << " values." << std::endl;
                return false;
            }

            // Prepare the columns (x axis)
            _tile_grid[layer_id].tiles[y].resize(_num_tile_on_x_axis);

            for(uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
                _tile_grid[layer_id].tiles[y][x] = table_x_indeces[x];
            }
        }
        map_file.CloseTable(); // layers[layer_id]
    }

    map_file.CloseTable(); // layers

    // Determine which tiles in each tileset are referenced in this map

    // Used to determine whether each tile is used by the map or not. An entry of -1 indicates that particular tile is not used
    std::vector<int16> tile_references;
    // Set size to be equal to the total number of tiles and initialize all entries to -1 (unreferenced)
    tile_references.assign(tileset_filenames.size() * TILES_PER_TILESET, -1);

    // For each layer
    for(uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
        // For each tile id
        for(uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
            for(uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
                if(_tile_grid[layer_id].tiles[y][x] >= 0)
                    tile_references[_tile_grid[layer_id].tiles[y][x] ] = 0;
            }
        }
    }

    // Translate the tileset tile indeces into indeces for the vector of tile images

    // Here, we have to convert the original tile indeces defined in the map file into a new form. The original index
    // indicates the tileset where the tile is used and its location in that tileset. We need to convert those indeces
    // so that they serve as an index to the MapMode::_tile_images vector, where the tile images will soon be stored.

    // Keeps track of the next translated index number to assign
    uint32 next_index = 0;

    for(uint32 i = 0; i < tile_references.size(); ++i) {
        if(tile_references[i] >= 0) {
            tile_references[i] = next_index;
            next_index++;
        }
    }

    // Now, go back and re-assign all tile layer indeces with the translated indeces
    // For each layer
    for(uint32 layer_id = 0; layer_id < layers_number; ++layer_id) {
        // For each tile id
        for(uint32 y = 0; y < _num_tile_on_y_axis; ++y) {
            for(uint32 x = 0; x < _num_tile_on_x_axis; ++x) {
                if(_tile_grid[layer_id].tiles[y][x] >= 0)
                    _tile_grid[layer_id].tiles[y][x] = tile_references[_tile_grid[layer_id].tiles[y][x] ];
            }
        }
    }

    // Parse all of the tileset definition files and create any animated tile images that will be used

    // Used to access the tileset definition file
    ReadScriptDescriptor tileset_script;
    // Temporarily retains the animation data (every two elements corresponds to a pair of tile frame index and display time)
    std::vector<uint32> animation_info;
    // Temporarily holds all animated tile images. The map key is the value of the tile index, before reference translation is done in the next step
    std::map<uint32, AnimatedImage *> tile_animations;

    for(uint32 i = 0; i < tileset_filenames.size(); i++) {
        if (!tileset_script.OpenFile(tileset_filenames[i])) {
            PRINT_ERROR << "map failed to load because it could not open a tileset definition file: "
                << tileset_filenames[i] << std::endl;
            return false;
        }

        if (!tileset_script.OpenTable("tileset")) {
            PRINT_ERROR << "map failed to load because it could not open the 'tileset' table from file: "
                << tileset_filenames[i] << std::endl;
            tileset_script.CloseFile();
            return false;
        }

        if(tileset_script.DoesTableExist("animated_tiles")) {
            tileset_script.OpenTable("animated_tiles");
            for(uint32 j = 1; j <= tileset_script.GetTableSize(); j++) {
                animation_info.clear();
                tileset_script.ReadUIntVector(j, animation_info);

                // The index of the first frame in the animation. (i * TILES_PER_TILESET) factors in which tileset the frame comes from
                uint32 first_frame_index = animation_info[0] + (i * TILES_PER_TILESET);

                // If the first tile frame index of this animation was not referenced anywhere in the map, then the animation is unused and
                // we can safely skip over it and move on to the next one. Otherwise if it is referenced, we have to construct the animated image
                if(tile_references[first_frame_index] == -1) {
                    continue;
                }

                AnimatedImage *new_animation = new AnimatedImage();
                new_animation->SetDimensions(2.0f, 2.0f);

                // Each pair of entries in the animation info indicate the tile frame index (k) and the time (k+1)
                for(uint32 k = 0; k < animation_info.size(); k += 2) {
                    new_animation->AddFrame(tileset_images[i][animation_info[k]], animation_info[k + 1]);
                }
                tile_animations.insert(std::make_pair(first_frame_index, new_animation));
            }
            tileset_script.CloseTable();
        }

        tileset_script.CloseTable();
        tileset_script.CloseFile();
    } // for (uint32 i = 0; i < tileset_filenames.size(); i++)

    // Add all referenced tiles to the _tile_images vector, in the proper order

    for(uint32 i = 0; i < tileset_images.size(); i++) {
        for(uint32 j = 0; j < TILES_PER_TILESET; j++) {
            uint32 reference = (i * TILES_PER_TILESET) + j;

            if(tile_references[reference] >= 0) {
                // Add the tile as a StillImage
                if(tile_animations.find(reference) == tile_animations.end()) {
                    _tile_images.push_back(new StillImage(tileset_images[i][j]));
                }

                // Add the tile as an AnimatedImage
                else {
                    _tile_images.push_back(tile_animations[reference]);
                    _animated_tile_images.push_back(tile_animations[reference]);
                    tile_animations.erase(reference);
                }
            }
        }
    }

    if(tile_animations.empty() == false) {
        IF_PRINT_WARNING(MAP_DEBUG) << "one or more tile animations that were created were not added into the map -- this is a memory leak" << std::endl;
    }

    // Remove all tileset images. Any tiles which were not added to _tile_images will no longer exist in memory
    tileset_images.clear();

    return true;
} // bool TileSupervisor::Load(ReadScriptDescriptor& map_file)
예제 #15
0
파일: layer.cpp 프로젝트: Ojaswi/inviwo
std::shared_ptr<LayerRepresentation> Layer::createDefaultRepresentation() const {
    return createLayerRAM(getDimensions(), getLayerType(), getDataFormat());
}
예제 #16
0
	string DataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
                string bottomStrEnd = "\"\n";

                string transformParamStrStart = "\ttransform_param\n\t{\n";
                string transformParamStrEnd ="\t}\n";

		string dataParamStrStart = "\tdata_param\n\t{\n";
		string dataParamStrEnd ="\t}\n";

		string SourceStrStart = "\t\tsource: ";
		string SourceStrEnd = "\n";

		string batchSizeStrStart = "\t\tbatch_size: ";
		string batchSizeStrEnd = "\n";

		string randSkipStrStart = "\t\trand_skip: ";
		string randSkipStrEnd = "\n";

		string backendStrStart = "\t\tbackend: ";
		string backendStrEnd = "\n";

		string ScaleStrStart = "\t\tscale: ";
		string ScaleStrEnd = "\n";

		string MeanFileStrStart = "\t\tmean_file: ";
		string MeanFileStrEnd = "\n";

		string CropSizeStrStart = "\t\tcrop_size: ";
		string CropSizeStrEnd = "\n";

		string MirrorStrStart = "\t\tmirror: ";
		string MirrorStrEnd = "\n";

		string ForceEncodeColorStrStart = "\t\tforce_encoded_color: ";
		string ForceEncodeColorStrEnd = "\n";

                string PrefetchStrStart =  "\t\tprefetch: ";
                string PrefetchStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr =  layerStrStart + 
						 nameStrStart + getLayerName() + nameStrEnd + 
						 typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] +bottomStrEnd;
		}

                outStr += transformParamStrStart;

                if(((DataParam*)mParam)->mScale != 1)
                {
                        outStr += ScaleStrStart + to_string(getScale()) + ScaleStrEnd;
                }

                if (getMeanfile() != "")
                {
                        outStr += MeanFileStrStart + "\"" + getMeanfile() + "\"" + MeanFileStrEnd;
                }

                if(((DataParam*)mParam)->mCropsize != 0)
                {
                        outStr += CropSizeStrStart + to_string(getCropsize()) + CropSizeStrEnd;
                }

                if(((DataParam*)mParam)->mMirror != false)
                {
                        outStr += MirrorStrStart + "true" + MirrorStrEnd;
                }
                outStr += transformParamStrEnd;

		outStr += dataParamStrStart;

                if (getSource() != "")
		{
			outStr += SourceStrStart + "\"" + getSource() + "\"" + SourceStrEnd;
		}

		outStr +=batchSizeStrStart + to_string(getBatchSize()) + batchSizeStrEnd;

		if(((DataParam*)mParam)->mRandSkip != 0)
		{
			outStr += randSkipStrStart + to_string(getRandSkip()) + randSkipStrEnd;
		}

		if(((DataParam*)mParam)->mBackend != DB::LEVELDB)
		{
			switch (((DataParam*)mParam)->mBackend)
			{
			case DB::LEVELDB:
					outStr += backendStrStart + "LEVELDB" + backendStrEnd;
					break;

			case DB::LMDB:
					outStr += backendStrStart + "LMDB" + backendStrEnd;
					break;
			}
		}

		if(((DataParam*)mParam)->mForceEncodedcolor != false)
		{
			outStr += ForceEncodeColorStrStart + "true" + ForceEncodeColorStrEnd;
		}

                if(((DataParam*)mParam)->mPrefetch != 4)
                {
                        outStr += PrefetchStrStart + to_string(getPrefetch())  + PrefetchStrEnd;
                }

		outStr += dataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #17
0
	string EltwiseLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string eltwiseParamStrStart = "\teltwise_param\n\t{\n";
		string eltwiseParamStrEnd = "\t}\n";

		string operationStrStart = "\t\toperation: ";
		string operationStrEnd = "\n";

		string coeffStrStart = "\t\tcoeff: ";
		string coeffStrEnd = "\n";

		string stableProdGradStrStart = "\t\tstable_prod_grad: ";
		string stableProdGradStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart  + mName         + nameStrEnd + 
						typeStrStart  + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + 
			     eltwiseParamStrStart   ;

                if(((EltwiseParam*)mParam)->mOperation != MMALab::ELTWISEOP_SUM)
		{
			switch (((EltwiseParam*)mParam)->mOperation)
			{
                        case MMALab::ELTWISEOP_PROD:
                                outStr += operationStrStart + "PROD" + operationStrEnd;
				break;
			case MMALab::ELTWISEOP_MAX:
				outStr += operationStrStart + "MAX" + operationStrEnd;
			}
		}
		outStr += coeffStrStart + to_string(getCoeff()) + coeffStrEnd;

		if(((EltwiseParam*)mParam)->mStableProdGrad != true)
		{
			outStr += stableProdGradStrStart + "false" + stableProdGradStrEnd;
		}
		outStr += eltwiseParamStrEnd ;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #18
0
	string MemoryDataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string memoryDataParamStrStart = "\tmemory_data_param\n\t{\n";
		string memoryDataParamStrEnd = "\t}\n";

		string batchSizeStrStart = "\t\tbatch_size: ";
		string batchSizeEnd = "\n";

		string channelsStrStart = "\t\tchannels: ";
		string channelsEnd = "\n";

		string heightStrStart = "\t\theight: ";
		string heightEnd = "\n";

		string widthStrStart = "\t\twidth: ";
		string widthEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart + mName + nameStrEnd + 
						typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}
		
		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + 
				 memoryDataParamStrStart + 
				 batchSizeStrStart + to_string(getBatchSize()) + batchSizeEnd +
				 channelsStrStart + to_string(getChannels()) + channelsEnd +
				 heightStrStart + to_string(getHeight()) + heightEnd +
				 widthStrStart + to_string(getWidth()) + widthEnd +
				 memoryDataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
예제 #19
0
	string PoolingLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string poolingParamStrStart = "\tpooling_param\n\t{\n";
		string poolingParamStrEnd = "\t}\n";

		string kernelSizeStrStart = "\t\tkernel_size: ";
		string kernelSizeStrEnd = "\n";

		/*string kernelHStrStart = "\t\tkernel_h: ";
		string kernelHStrEnd = "\n";

		string kernelWStrStart = "\t\tkernel_w: ";
		string kernelWStrEnd = "\n";*/

		string strideStrStart = "\t\tstride: ";
		string strideStrEnd = "\n";
		/*string strideHStrStart = "\t\tstride_h: ";
		string strideHStrEnd = "\n";
		string strideWStrStart = "\t\tstride_w: ";
		string strideWStrEnd = "\n";*/

		string padStrStart = "\t\tpad: ";
		string padStrEnd = "\n";
		/*string padHStrStart = "\t\tpad_h: ";
		string padHStrEnd = "\n";
		string padWStrStart = "\t\tpad_w: ";
		string padWStrEnd = "\n";*/

		string poolStrStart = "\t\tpool: ";
		string poolStrEnd = "\n";

		string engineStrStart = "\t\tengine: ";
		string engineStrEnd = "\n";

		string globalPoolingStrStart = "\t\tglobal_pooling: ";
		string globalPoolingStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart+
						nameStrStart + mName + nameStrEnd + 
						typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr += poolingParamStrStart;	



		if (((PoolingParam*)mParam)->mPool != MMALab::POOLMETHOD_MAX)

		{
			switch (((PoolingParam*)mParam)->mPool)
			{
			case MMALab::POOLMETHOD_AVE:
				outStr += poolStrStart + "AVE" + poolStrEnd;
				break;
			case MMALab::POOLMETHOD_STOCHASTIC:
				outStr += poolStrStart + "STOCHASTIC" + poolStrEnd;
				break;
			}
		}

		if (((PoolingParam*)mParam)->mPad != 0)
		{
			outStr += padStrStart + to_string(getPad()) + padStrEnd;
		}
		/*if (((PoolingParam*)mParam)->mPadH != 0)
		{
			outStr += padHStrStart + to_string(getPadH()) + padHStrEnd;
		}
		if (((PoolingParam*)mParam)->mPadW != 0)
		{
			outStr += padWStrStart + to_string(getPadW()) + padWStrEnd;
		}*/

		outStr += kernelSizeStrStart   + to_string(getKernelSize()) + kernelSizeStrEnd;
		/*outStr += kernelHStrStart   + to_string(getKernelH()) + kernelHStrEnd;
		outStr += kernelWStrStart   + to_string(getKernelW()) + kernelWStrEnd;*/

		if (((PoolingParam*)mParam)->mStride != 1)
		{
			outStr += strideStrStart + to_string(getStride()) + strideStrEnd;
		}
		/*if (((PoolingParam*)mParam)->mStrideH != 1)
		{
			outStr += strideHStrStart + to_string(getStrideH()) + strideHStrEnd;
		}
		if (((PoolingParam*)mParam)->mStrideW != 1)
		{
			outStr += strideWStrStart + to_string(getStrideW()) + strideWStrEnd;
		}*/

		if (((PoolingParam*)mParam)->mEngine != MMALab::DEFAULT)
		{
			switch (((PoolingParam*)mParam)->mEngine)
			{
			case MMALab::CAFFE:
				outStr += engineStrStart + "CAFFE" + engineStrEnd;
				break;

			case MMALab::CUDNN:
				outStr += engineStrStart + "CUDNN" + engineStrEnd;
				break;
			}
		}

		if (((PoolingParam*)mParam)->mGlobalPooling != false)
		{
			outStr += globalPoolingStrStart + "true" + globalPoolingStrEnd;
		}

		outStr += poolingParamStrEnd;		
				
		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;	
	}
예제 #20
0
	string WindowDataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string WindowDataParamStrStart = "\twindow_data_param\n\t{\n";
		string WindowDataParamStrEnd = "\t}\n";

		string SourceStrStart = "\t\tsource: ";
		string SourceStrEnd = "\n";

		string ScaleStrStart = "\t\tscale: ";
		string ScaleStrEnd = "\n";

		string MeanFileStrStart = "\t\tmean_file: ";
		string MeanFileStrEnd = "\n";

		string BatchSizeStrStart = "\t\tbatch_size: ";
		string BatchSizeStrEnd = "\n";

		string CropSizeStrStart = "\t\tcrop_size: ";
		string CropSizeStrEnd = "\n";

		string MirrorStrStart = "\t\tmirror: ";
		string MirrorStrEnd = "\n";

		string FgThresholdStrStrat = "\t\tfg_threshold: ";
		string FgThresholdStrEnd = "\n";

		string BgThresholdStrStrat = "\t\tbg_threshold: ";
		string BgThresholdStrEnd = "\n";

		string FgFractionStrStart = "\t\tfg_fraction: ";
		string FgFractionStrEnd = "\n";

		string ContextPadStrStart = "\t\tcontext_pad: "; 
		string ContextPadStrEnd = "\n";

		string CropModeStrStart = "\t\tcrop_mode: ";
		string CropModeStrEnd = "\n";

		string CacheImagesStrStart = "\t\tcache_images: ";
		string CacheImagesStrEnd = "\n";

		string RootFolderStrStart = "\t\troot_folder: ";
		string RootFolderStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr =  layerStrStart + 
						 nameStrStart + mName + nameStrEnd + 
						 typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] +bottomStrEnd;
		}

		outStr += WindowDataParamStrStart;

		if (getSource() == "")
		{

		}
		else
		{
			outStr += SourceStrStart + "\"" + getSource() + "\"" + SourceStrEnd;;
		}

		if(((WindowDataParam*)mParam)->mScale != 1)
		{
			outStr += ScaleStrStart + to_string(getScale()) + ScaleStrEnd;
		}
		
		if (getMeanFile() == "")
		{

		}
		else
		{
			outStr += MeanFileStrStart + "\"" + getMeanFile() + "\"" + MeanFileStrEnd;
		}

		outStr += BatchSizeStrStart + to_string(getBatchSize()) + BatchSizeStrEnd;

		if(((WindowDataParam*)mParam)->mCropSize != 0)
		{
			outStr += CropSizeStrStart + to_string(getCropSize()) + CropSizeStrEnd;
		}

		if(((WindowDataParam*)mParam)->mMirror != false)
		{
			outStr += MirrorStrStart + "true" + MirrorStrEnd;
		}

		if(((WindowDataParam*)mParam)->mFgThreshold != 0.5)
		{
			outStr += FgThresholdStrStrat + to_string(getFgThreshold()) + FgFractionStrEnd;
		}

		if(((WindowDataParam*)mParam)->mBgThreshold != 0.5)
		{
			outStr += BgThresholdStrStrat + to_string(getBgThreshold()) + BgThresholdStrEnd;
		}

		if(((WindowDataParam*)mParam)->mFgFraction != 0.25)
		{
			outStr += FgFractionStrStart + to_string(getFgFraction()) + FgFractionStrEnd;
		}

		if(((WindowDataParam*)mParam)->mContextPad != 0)
		{
			outStr += ContextPadStrStart + to_string(getContextPad()) + ContextPadStrEnd;
		}

		if(((WindowDataParam*)mParam)->mCropMode != CropMode::WARP)
		{
			outStr += CropModeStrStart + "\"" + "square" + "\"" + CropModeStrEnd;
		}
		
		if(((WindowDataParam*)mParam)->mCacheImages != false)
		{
			outStr +=  CacheImagesStrStart + "true" + CacheImagesStrEnd;
		}

		if(((WindowDataParam*)mParam)->mRootFolder != "")
		{
			outStr +=  RootFolderStrStart + "\"" + getRootFolder() + "\"" + RootFolderStrEnd ;
		}

		outStr += WindowDataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;
		
		return outStr;
	}