Use the new layer info data in the simulator.
This commit is contained in:
@@ -10,10 +10,9 @@
|
|||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
LayerData::LayerData(const string& name, const vector<int>& shape, const DType* data, Type type) :
|
LayerData::LayerData(const string& name, const vector<int>& shape, const DType* data) :
|
||||||
name_(name),
|
name_(name),
|
||||||
shape_(shape),
|
shape_(shape)
|
||||||
type_(type)
|
|
||||||
{
|
{
|
||||||
const auto dataSize = numEntries();
|
const auto dataSize = numEntries();
|
||||||
// Compute the dimension of the data area
|
// Compute the dimension of the data area
|
||||||
@@ -25,7 +24,7 @@ LayerData::LayerData(const string& name, const vector<int>& shape, const DType*
|
|||||||
|
|
||||||
size_t LayerData::numEntries() const
|
size_t LayerData::numEntries() const
|
||||||
{
|
{
|
||||||
return accumulate(shape_.begin(), shape_.end(), 1, multiplies<>());
|
return static_cast<size_t>(accumulate(shape_.begin(), shape_.end(), 1, multiplies<>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<int>& LayerData::shape() const
|
const vector<int>& LayerData::shape() const
|
||||||
@@ -33,11 +32,6 @@ const vector<int>& LayerData::shape() const
|
|||||||
return shape_;
|
return shape_;
|
||||||
}
|
}
|
||||||
|
|
||||||
typename LayerData::Type LayerData::type() const
|
|
||||||
{
|
|
||||||
return type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string& LayerData::name() const
|
const string& LayerData::name() const
|
||||||
{
|
{
|
||||||
return name_;
|
return name_;
|
||||||
@@ -48,22 +42,6 @@ DType const * LayerData::data() const
|
|||||||
return data_.get();
|
return data_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerData::Type LayerData::typeFromString(string_view typeName)
|
|
||||||
{
|
|
||||||
if (typeName == "Input") {
|
|
||||||
return Type::Input;
|
|
||||||
} else if (typeName == "Convolution") {
|
|
||||||
return Type::Convolutional;
|
|
||||||
} else if (typeName == "ReLU") {
|
|
||||||
return Type::ReLU;
|
|
||||||
} else if (typeName == "Pooling") {
|
|
||||||
return Type::Pooling;
|
|
||||||
} else {
|
|
||||||
LOG(INFO) << "Received unknown layer type: " << typeName << endl;
|
|
||||||
return Type::Other;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream& operator<< (ostream& o, const LayerData& layer)
|
ostream& operator<< (ostream& o, const LayerData& layer)
|
||||||
{
|
{
|
||||||
o << layer.name() << '(';
|
o << layer.name() << '(';
|
||||||
|
|||||||
@@ -20,17 +20,7 @@ namespace fmri
|
|||||||
class LayerData
|
class LayerData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Type
|
LayerData(const string &name, const vector<int> &shape, const DType *data);
|
||||||
{
|
|
||||||
Input,
|
|
||||||
Convolutional,
|
|
||||||
ReLU,
|
|
||||||
Pooling,
|
|
||||||
Output,
|
|
||||||
Other
|
|
||||||
};
|
|
||||||
|
|
||||||
LayerData(const string &name, const vector<int> &shape, const DType *data, Type type);
|
|
||||||
LayerData(const LayerData &) = delete;
|
LayerData(const LayerData &) = delete;
|
||||||
|
|
||||||
LayerData(LayerData &&) = default;
|
LayerData(LayerData &&) = default;
|
||||||
@@ -38,18 +28,13 @@ namespace fmri
|
|||||||
LayerData &operator=(LayerData &&) = default;
|
LayerData &operator=(LayerData &&) = default;
|
||||||
|
|
||||||
const string &name() const;
|
const string &name() const;
|
||||||
Type type() const;
|
|
||||||
const vector<int> &shape() const;
|
const vector<int> &shape() const;
|
||||||
DType const *data() const;
|
DType const *data() const;
|
||||||
size_t numEntries() const;
|
size_t numEntries() const;
|
||||||
|
|
||||||
static Type typeFromString(string_view name);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string name_;
|
string name_;
|
||||||
vector<int> shape_;
|
vector<int> shape_;
|
||||||
unique_ptr<DType[]> data_;
|
unique_ptr<DType[]> data_;
|
||||||
Type type_;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,3 +31,8 @@ const std::string &LayerInfo::name() const
|
|||||||
{
|
{
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LayerInfo::Type LayerInfo::type() const
|
||||||
|
{
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace fmri
|
|||||||
const std::vector<boost::shared_ptr<caffe::Blob<DType>>> ¶meters);
|
const std::vector<boost::shared_ptr<caffe::Blob<DType>>> ¶meters);
|
||||||
|
|
||||||
const std::string& name() const;
|
const std::string& name() const;
|
||||||
|
Type type() const;
|
||||||
|
|
||||||
static Type typeByName(std::string_view name);
|
static Type typeByName(std::string_view name);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <opencv2/imgproc/imgproc.hpp>
|
#include <opencv2/imgproc/imgproc.hpp>
|
||||||
|
|
||||||
#include "Simulator.hpp"
|
#include "Simulator.hpp"
|
||||||
#include "utils.hpp"
|
|
||||||
|
|
||||||
using namespace caffe;
|
using namespace caffe;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -92,8 +91,6 @@ void Simulator::Impl::loadMeans(const string &means_file)
|
|||||||
|
|
||||||
vector<LayerData> Simulator::Impl::simulate(const string& image_file)
|
vector<LayerData> Simulator::Impl::simulate(const string& image_file)
|
||||||
{
|
{
|
||||||
typedef LayerData::Type LType;
|
|
||||||
|
|
||||||
cv::Mat im = cv::imread(image_file, -1);
|
cv::Mat im = cv::imread(image_file, -1);
|
||||||
|
|
||||||
assert(!im.empty());
|
assert(!im.empty());
|
||||||
@@ -115,7 +112,7 @@ vector<LayerData> Simulator::Impl::simulate(const string& image_file)
|
|||||||
CHECK_EQ(results[i].size(), 1) << "Multiple outputs per layer are not supported!" << endl;
|
CHECK_EQ(results[i].size(), 1) << "Multiple outputs per layer are not supported!" << endl;
|
||||||
const auto blob = results[i][0];
|
const auto blob = results[i][0];
|
||||||
|
|
||||||
result.emplace_back(names[i], blob->shape(), blob->cpu_data(), LayerData::typeFromString(layers[i]->type()));
|
result.emplace_back(names[i], blob->shape(), blob->cpu_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ using namespace fmri;
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
optional<vector<string>> labels;
|
optional<vector<string>> labels;
|
||||||
|
map<string, LayerInfo> layerInfo;
|
||||||
vector<vector<LayerData>> data;
|
vector<vector<LayerData>> data;
|
||||||
vector<vector<LayerData>>::iterator currentData;
|
vector<vector<LayerData>>::iterator currentData;
|
||||||
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
||||||
@@ -30,6 +31,7 @@ static vector<vector<LayerData>> getSimulationData(const Options &options)
|
|||||||
vector<vector<LayerData>> results;
|
vector<vector<LayerData>> results;
|
||||||
auto dumper = options.imageDumper();
|
auto dumper = options.imageDumper();
|
||||||
Simulator simulator(options.model(), options.weights(), options.means());
|
Simulator simulator(options.model(), options.weights(), options.means());
|
||||||
|
rendererData.layerInfo = simulator.layerInfo();
|
||||||
|
|
||||||
for (const auto &image : options.inputs()) {
|
for (const auto &image : options.inputs()) {
|
||||||
results.emplace_back(simulator.simulate(image));
|
results.emplace_back(simulator.simulate(image));
|
||||||
|
|||||||
Reference in New Issue
Block a user