예제 #1
0
    void qt_gui_settings::unserialize(core::coll_helper _collection)
    {
        core::iarray* values_array = _collection.get_value_as_array("values");
        if (!values_array)
        {
            assert(false);
            return;
        }

        for (int i = 0; i < values_array->size(); ++i)
        {
            const core::ivalue* val = values_array->get_at(i);

            gui_coll_helper coll_val(val->get_as_collection(), false);

            core::istream* idata = coll_val.get_value_as_stream("value");

            int len = idata->size();

            set_value_simple_data(coll_val.get_value_as_string("name"), (const char*) idata->read(len), len, false);
        }

        emit received();
        setIsLoaded(true);
    }
예제 #2
0
void TimeSeriesMotion::setDataColumn(int column)
{
    if (m_dataColumn != column) {
        m_dataColumn = column;
        emit dataColumnChanged(column);

        setIsLoaded(false);
    }
}
예제 #3
0
void TimeSeriesMotion::setStopLine(int line)
{
    if (m_stopLine != line) {
        m_stopLine = line;
        emit stopLineChanged(line);

        setIsLoaded(false);
    }
}
예제 #4
0
void TimeSeriesMotion::setFormat(Format format)
{
    if (m_format != format) {
        m_format = format;
        emit formatChanged(format);

        setIsLoaded(false);
    }
}
예제 #5
0
void TimeSeriesMotion::setPointCount(int count)
{
    if (m_pointCount != count) {
        m_pointCount = count;
        emit pointCountChanged(count);

        setIsLoaded(false);
    }
}
예제 #6
0
void TimeSeriesMotion::setTimeStep(double timeStep)
{
    if (fabs(m_timeStep - timeStep) > DBL_EPSILON) {
        m_timeStep = timeStep;

        emit timeStepChanged(m_timeStep);

        setIsLoaded(false);
    }
}
예제 #7
0
void TimeSeriesMotion::setFileName(const QString & fileName)
{    
    QFileInfo fileInfo(fileName);
    const QString _fileName = QDir::cleanPath(fileInfo.absoluteFilePath());

    if (m_fileName != _fileName) {
        emit fileNameChanged(_fileName);
    }

    m_fileName = _fileName;   
    setIsLoaded(false);
}
예제 #8
0
void TimeSeriesMotion::setInputUnits(TimeSeriesMotion::InputUnits inputUnits)
{
    if (m_inputUnits != inputUnits) {
        // Save the previously used conversation and scale factors
        const double prevFactor = unitConversionFactor();
        const double prevScale = m_scale;

        m_inputUnits = inputUnits;
        setModified(true);

        // Need to modify the scale to correct for the change in units.
        // This is done by modifying the m_scale parameter which is then
        // used in rescale the appropriate values.
        m_scale *= prevFactor / unitConversionFactor();
        setScale(prevScale);

        emit inputUnitsChanged(inputUnits);
    }

    setIsLoaded(false);
}
예제 #9
0
void TensorFlowEngine::load() {
	const auto networkFilename = getFilename();
	tensorflow::SessionOptions options;
	tensorflow::ConfigProto &config = options.config;
	tensorflow::GPUOptions* gpuOptions = config.mutable_gpu_options();
	gpuOptions->set_allow_growth(true); // Set this so that tensorflow will not use up all GPU memory
	//gpuOptions->set_per_process_gpu_memory_fraction(0.5);
	mSession.reset(tensorflow::NewSession(options));
	tensorflow::GraphDef tensorflow_graph;

	{
		reportInfo() << "Loading network file: " << networkFilename << reportEnd();
		tensorflow::Status s = ReadBinaryProto(tensorflow::Env::Default(), networkFilename, &tensorflow_graph);
		if (!s.ok()) {
			throw Exception("Could not read TensorFlow graph file " + networkFilename);
		}
	}

	bool nodesSpecified = true;
    int inputCounter = 0;
	if(mInputNodes.size() == 0) {
		nodesSpecified = false;
	}
    for(int i = 0; i < tensorflow_graph.node_size(); ++i) {
		tensorflow::NodeDef node = tensorflow_graph.node(i);
		if(mInputNodes.count(node.name()) > 0) {
		}
		if(node.op() == "Placeholder") {
			if(node.name().find("keras_learning_phase") != std::string::npos) {
				//mLearningPhaseTensors.insert(node.name());
				mLearningPhaseTensors.push_back(node.name());
			} else {
				// Input node found:
				// Get its shape
				// Input nodes use the Op Placeholder
				reportInfo() << "Found input node: " << i << " with name " << node.name() << reportEnd();
				auto shape = getShape(node);
				reportInfo() << "Node has shape " << shape.toString() << reportEnd();
				if(mInputNodes.count(node.name()) == 0) {
					if(nodesSpecified) {
						throw Exception("Encountered unknown node " + node.name());
					}
					reportInfo() << "Node was not specified by user" << reportEnd();
					// If node has not been specified by user, we need to add it
					// and thus know its type (fast image or tensor)
					// It is assumed to be an image if input shape has at least 4 dimensions
					NodeType type = NodeType::TENSOR;
					if(shape.getKnownDimensions() >= 2) {
						reportInfo() << "Assuming node is an image" << reportEnd();
						type = NodeType::IMAGE;
					} else {
						reportInfo() << "Assuming node is a tensor" << reportEnd();
					}
					addInputNode(inputCounter, tensorflow_graph.node(0).name(), type, shape);
					++inputCounter;
				}

				// Set its shape
				mInputNodes[node.name()].shape = shape;
			}
		}
	}

	reportInfo() << "Creating session." << reportEnd();
	tensorflow::Status s = mSession->Create(tensorflow_graph);
	if (!s.ok()) {
		throw Exception("Could not create TensorFlow Graph");
	}

	//tensorflow::graph::SetDefaultDevice("/gpu:0", &tensorflow_graph);

	// Clear the proto to save memory space.
	tensorflow_graph.Clear();
	reportInfo() << "TensorFlow graph loaded from: " << networkFilename << reportEnd();

	setIsLoaded(true);
}
예제 #10
0
bool TimeSeriesMotion::load(const QString &fileName, bool defaults, double scale)
{
    m_accel.clear();

    setFileName(fileName);
    const QString ext = m_fileName.right(3).toUpper();

    // Load the file
    QFile file(m_fileName);
    if (!file.open( QIODevice::ReadOnly | QIODevice::Text )) {
        qWarning() << "Unable to open the time series file:" << qPrintable(m_fileName);
        return false;
    }
    QTextStream stream(&file);

    if (defaults) {
        if (ext == "AT2") {
            // Set format
            setFormat(Rows);
            setStartLine(5);
            setStopLine(0);
            setScale(scale);

            // Read in the header information
            Q_UNUSED(stream.readLine());

            setDescription(stream.readLine());

            Q_UNUSED(stream.readLine());

            QStringList parts = stream.readLine().split(QRegExp("\\s+"));

            bool b;
            const int count = parts.at(0).toInt(&b);
            if (b && count > 1) {
                // Greater than one condition to catch if an acceleration value is read
                setPointCount(count);
            } else {
                qCritical() << "Unable to parse the point count in AT2 file!";
                return false;
            }

            const double timeStep = parts.at(1).toDouble(&b);

            if (b) {
                setTimeStep(timeStep);
            } else {
                qCritical() << "Unable to parse the time step in AT2 file!";
                return false;
            }
        } else {
            // Unknown file format can't process with default settings
            return false;
        }
    } else {
        // Check the input
        if (m_timeStep <= 0) {
            qCritical("Time step must be greater than one");
            return false;
        }
        if (m_startLine < 0) {
            qCritical("Number of header lines must be positive");
            return false;
        }
    }

    // Move back to the start of the stream
    stream.seek(0);

    int lineNum = 1;
    // Skip the header lines
    while (lineNum < m_startLine) {
        Q_UNUSED(stream.readLine());
        ++lineNum;
    }

    // Initialize the length of m_accel
    m_accel.resize(m_pointCount);

    // Process each of the lines
    int index = 0;
    // Read the first line
    QString line =stream.readLine();

    bool finished = false;
    bool stopLineReached = false;

    // Modify the scale for unit conversion
    scale = unitConversionFactor() * m_scale;

    while (!finished && !line.isNull()) {
        // Stop if line exceeds number of lines.  The line number has
        // to be increased by one because the user display starts at
        // line number 1 instead of 0
        if (m_stopLine > 0 &&  m_stopLine <= lineNum+1) {
            stopLineReached = true;
            break;
        }

        // Read the line and split the line
        QRegExp rx("(-?\\d*\\.\\d+(?:[eE][+-]?\\d+)?)");
        int pos = 0;
        QStringList row;

        while ((pos = rx.indexIn(line, pos)) != -1) {
            row << rx.cap(1);
            pos += rx.matchedLength();
        }

        // Process the row based on the format
        bool ok;
        switch (m_format) {
        case Rows:
            // Use all parts of the data
            for(int i = 0; i < row.size(); ++i) {
                if ( index == m_pointCount ) {
                    qWarning("Point count reached before end of data!");
                    finished = true;
                    break;
                }
                // Apply the scale factor and read the acceleration
                m_accel[index] = scale * row.at(i).trimmed().toDouble(&ok);
                // Increment the index
                ++index;
                // Stop if there was an error in the conversion
                if (!ok) {
                    continue;
                }
            }
            break;
                case Columns:
            // Use only the important column, however at the end of the
            // file that column may not exist -- this only happens when the
            // row format is applied, but it still causes the program to
            // crash.
            if ( m_dataColumn - 1 < row.size() ) {
                m_accel[index] = scale * row.at(m_dataColumn-1).trimmed().toDouble(&ok);
            }

            // Increment the index
            ++index;
            break;
        }

        // Throw an error if there was a problem
        if (!ok) {
            qCritical() << "Error converting string to double in line: \n\""
                    << qPrintable(line) << "\"\nCheck starting line.";
            return false;
        }

        // Read the next line
        ++lineNum;
        line = stream.readLine();
    }

    if (m_pointCount != index) {
        if (stopLineReached) {
            qWarning() << "Number of points limited by stop line.";
        } else {
            qCritical() << "Number of points read does not equal specified point count!";
            return false;
        }
    }

    // Compute motion properties
    calculate();

    setIsLoaded(true);
    return true;
}