Clean up on layer visualisations.
This commit is contained in:
16
src/DummyLayerVisualisation.hpp
Normal file
16
src/DummyLayerVisualisation.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "LayerVisualisation.hpp"
|
||||
|
||||
namespace fmri
|
||||
{
|
||||
/**
|
||||
* Visualisation that does not actually do anything.
|
||||
*/
|
||||
class DummyLayerVisualisation : public LayerVisualisation
|
||||
{
|
||||
public:
|
||||
void render() override
|
||||
{};
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,8 @@ LayerInfo::Type LayerInfo::typeByName(string_view name)
|
||||
return Type::ReLU;
|
||||
} else if (name == "Pooling") {
|
||||
return Type::Pooling;
|
||||
} else if (name == "InnerProduct") {
|
||||
return Type::InnerProduct;
|
||||
} else {
|
||||
LOG(INFO) << "Received unknown layer type: " << name << endl;
|
||||
return Type::Other;
|
||||
@@ -24,7 +26,6 @@ LayerInfo::LayerInfo(string_view name, string_view type,
|
||||
const vector<boost::shared_ptr<caffe::Blob<DType>>> ¶meters)
|
||||
: parameters_(parameters), type_(typeByName(type)), name_(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const std::string &LayerInfo::name() const
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace fmri
|
||||
ReLU,
|
||||
Pooling,
|
||||
Output,
|
||||
InnerProduct,
|
||||
Other
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <GL/glut.h>
|
||||
#include <GL/freeglut.h>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
@@ -60,7 +60,8 @@ static void handleKeys(unsigned char key, int, int)
|
||||
|
||||
case 'q':
|
||||
// Utility quit function.
|
||||
exit(0);
|
||||
glutLeaveMainLoop();
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
camera.reset();
|
||||
|
||||
@@ -16,6 +16,6 @@ namespace fmri
|
||||
static Camera& instance();
|
||||
|
||||
private:
|
||||
Camera() = default;
|
||||
Camera() noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
38
src/main.cpp
38
src/main.cpp
@@ -14,6 +14,8 @@
|
||||
#include "FlatLayerVisualisation.hpp"
|
||||
#include "MultiImageVisualisation.hpp"
|
||||
#include "Range.hpp"
|
||||
#include "ActivityAnimation.hpp"
|
||||
#include "DummyLayerVisualisation.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace fmri;
|
||||
@@ -25,6 +27,7 @@ struct
|
||||
vector<vector<LayerData>> data;
|
||||
vector<vector<LayerData>>::iterator currentData;
|
||||
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
||||
vector<unique_ptr<ActivityAnimation>> animations;
|
||||
} rendererData;
|
||||
|
||||
static void loadSimulationData(const Options &options)
|
||||
@@ -84,6 +87,8 @@ static void render()
|
||||
glPopMatrix();
|
||||
glTranslatef(-10, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glutSwapBuffers();
|
||||
@@ -98,24 +103,15 @@ static void renderLayerName(const LayerData &data)
|
||||
glTranslatef(0, 0, -10);
|
||||
}
|
||||
|
||||
static LayerVisualisation *getVisualisationForLayer(const LayerData &layer);
|
||||
|
||||
static void updateVisualisers()
|
||||
{
|
||||
rendererData.layerVisualisations.clear();
|
||||
rendererData.animations.clear();
|
||||
|
||||
for (auto &layer : *rendererData.currentData) {
|
||||
LayerVisualisation* visualisation = nullptr;
|
||||
switch (layer.shape().size()) {
|
||||
case 2:
|
||||
visualisation = new FlatLayerVisualisation(layer, FlatLayerVisualisation::Ordering::SQUARE);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
visualisation = new MultiImageVisualisation(layer);
|
||||
break;
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
for (LayerData &layer : *rendererData.currentData) {
|
||||
LayerVisualisation* visualisation = getVisualisationForLayer(layer);
|
||||
|
||||
rendererData.layerVisualisations.emplace_back(visualisation);
|
||||
}
|
||||
@@ -123,6 +119,20 @@ static void updateVisualisers()
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
LayerVisualisation *getVisualisationForLayer(const LayerData &layer)
|
||||
{
|
||||
switch (layer.shape().size()) {
|
||||
case 2:
|
||||
return new FlatLayerVisualisation(layer, FlatLayerVisualisation::Ordering::SQUARE);
|
||||
|
||||
case 4:
|
||||
return new MultiImageVisualisation(layer);
|
||||
|
||||
default:
|
||||
return new DummyLayerVisualisation();
|
||||
}
|
||||
}
|
||||
|
||||
static void specialKeyFunc(int key, int, int)
|
||||
{
|
||||
switch (key) {
|
||||
|
||||
Reference in New Issue
Block a user