Use the new layer info data in the simulator.
This commit is contained in:
@@ -10,10 +10,9 @@
|
||||
using namespace fmri;
|
||||
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),
|
||||
shape_(shape),
|
||||
type_(type)
|
||||
shape_(shape)
|
||||
{
|
||||
const auto dataSize = numEntries();
|
||||
// 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
|
||||
{
|
||||
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
|
||||
@@ -33,11 +32,6 @@ const vector<int>& LayerData::shape() const
|
||||
return shape_;
|
||||
}
|
||||
|
||||
typename LayerData::Type LayerData::type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
const string& LayerData::name() const
|
||||
{
|
||||
return name_;
|
||||
@@ -48,22 +42,6 @@ DType const * LayerData::data() const
|
||||
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)
|
||||
{
|
||||
o << layer.name() << '(';
|
||||
|
||||
@@ -20,17 +20,7 @@ namespace fmri
|
||||
class LayerData
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Input,
|
||||
Convolutional,
|
||||
ReLU,
|
||||
Pooling,
|
||||
Output,
|
||||
Other
|
||||
};
|
||||
|
||||
LayerData(const string &name, const vector<int> &shape, const DType *data, Type type);
|
||||
LayerData(const string &name, const vector<int> &shape, const DType *data);
|
||||
LayerData(const LayerData &) = delete;
|
||||
|
||||
LayerData(LayerData &&) = default;
|
||||
@@ -38,18 +28,13 @@ namespace fmri
|
||||
LayerData &operator=(LayerData &&) = default;
|
||||
|
||||
const string &name() const;
|
||||
Type type() const;
|
||||
const vector<int> &shape() const;
|
||||
DType const *data() const;
|
||||
size_t numEntries() const;
|
||||
|
||||
static Type typeFromString(string_view name);
|
||||
|
||||
private:
|
||||
string name_;
|
||||
vector<int> shape_;
|
||||
unique_ptr<DType[]> data_;
|
||||
Type type_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -31,3 +31,8 @@ const std::string &LayerInfo::name() const
|
||||
{
|
||||
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::string& name() const;
|
||||
Type type() const;
|
||||
|
||||
static Type typeByName(std::string_view name);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "Simulator.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace caffe;
|
||||
using namespace std;
|
||||
@@ -92,8 +91,6 @@ void Simulator::Impl::loadMeans(const string &means_file)
|
||||
|
||||
vector<LayerData> Simulator::Impl::simulate(const string& image_file)
|
||||
{
|
||||
typedef LayerData::Type LType;
|
||||
|
||||
cv::Mat im = cv::imread(image_file, -1);
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
@@ -20,6 +20,7 @@ using namespace fmri;
|
||||
struct
|
||||
{
|
||||
optional<vector<string>> labels;
|
||||
map<string, LayerInfo> layerInfo;
|
||||
vector<vector<LayerData>> data;
|
||||
vector<vector<LayerData>>::iterator currentData;
|
||||
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
||||
@@ -30,6 +31,7 @@ static vector<vector<LayerData>> getSimulationData(const Options &options)
|
||||
vector<vector<LayerData>> results;
|
||||
auto dumper = options.imageDumper();
|
||||
Simulator simulator(options.model(), options.weights(), options.means());
|
||||
rendererData.layerInfo = simulator.layerInfo();
|
||||
|
||||
for (const auto &image : options.inputs()) {
|
||||
results.emplace_back(simulator.simulate(image));
|
||||
|
||||
Reference in New Issue
Block a user