Browse Source

tsne updated

tsns-map
cailean 3 months ago
parent
commit
4eb21c1fa7
  1. 9
      .vscode/c_cpp_properties.json
  2. 8
      addons.make
  3. 70
      src/Map.cpp
  4. 65
      src/Map.h
  5. 2
      src/ofApp.cpp
  6. 3
      src/ofApp.h

9
.vscode/c_cpp_properties.json

@ -107,7 +107,14 @@
"${workspaceRoot}",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/src",
"/usr/local/onnxruntime-linux-x64-gpu-1.19.2/include",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/libs/opencv/include/opencv4"
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/libs/opencv/include/opencv4",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/src",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxNetwork/src",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxGui/src",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxTSNE/src",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/libs/oscpack/src/osc",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/libs/oscpack/src/ip",
"/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxTSNE/src/bhtsne"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,

8
addons.make

@ -1,2 +1,10 @@
ofxOpenCv
ofxOpenCv
ofxOsc
ofxOsc
ofxNetwork
ofxNetwork
ofxGui
ofxGui
ofxTSNE
ofxTSNE

70
src/Map.cpp

@ -0,0 +1,70 @@
#include "Map.h"
Map::Map(){
}
void Map::Setup(){
ofDisableArbTex();
isDebug = true;
json_embeddings = ofLoadJson(jsonPath);
if(!json_embeddings.is_array()){
ofLogError() << "JSON is not an array";
return;
} else {
std::cout << "JSON LOADED" << std::endl;
SetupTSNE();
}
mapFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA);
}
void Map::Update(){
}
void Map::Draw(){
}
void Map::SetupNodes(){
}
void Map::SetupTSNE(){
for (const auto& entry: json_embeddings) {
if (entry.contains("vector") && entry["vector"].is_array()) {
Node n;
n.foldername = entry["folder"];
n.image_path = entry["image"];
n.isLost = entry["lost"].get<int>();
std::vector<float> emb;
for (const auto& value: entry["vector"]){
if(value.is_number()){
emb.push_back(value.get<float>());
} else {
ofLogError() << "Vector value is not a number";
}
}
n.emotion_vector = emb;
nodes.push_back(n);
embeddings.push_back(emb);
}
}
std::cout << nodes.size() << std::endl;
std::cout << embeddings.size() << std::endl;
points = tsne.run(embeddings, dims, perplexity, theta, normalise, runManually);
for (size_t i = 0; i < points.size(); i++){
const auto& vec = points[i];
auto& n = nodes[i];
n.position = glm::vec3(vec[0], vec[1], vec[2]);
}
}

65
src/Map.h

@ -0,0 +1,65 @@
#ifndef _MAP
#define _MAP
#include "ofMain.h"
#include "ofxOsc.h"
#include "ofxTSNE.h"
struct Node {
glm::vec2 speed;
glm::vec2 amplitude;
glm::vec2 phase;
ofImage texture;
glm::vec3 position;
std::string image_path;
std::string foldername;
std::vector<float> emotion_vector;
int isLost;
};
class Map {
public:
/*
Constructor
*/
Map();
/*
Methods
*/
void Setup();
void Update();
void Draw();
void SetupNodes();
void SetupTSNE();
/*
Variables
*/
bool isDebug;
ofFbo mapFbo;
vector<ofPlanePrimitive> geoms;
vector<Node> nodes;
ofxTSNE tsne;
vector<vector<double>> points;
vector<vector<float>> embeddings;
int dims = 3;
float perplexity = 20;
float theta = 0.2;
bool normalise = true;
bool runManually = false;
ofJson json_embeddings;
std::string jsonPath = "data/json/embeddings.json";
private:
};
#endif

2
src/ofApp.cpp

@ -5,6 +5,8 @@ void ofApp::setup(){
ofSetFrameRate(24);
ofSetVerticalSync(true);
map.Setup();
player.Setup();
player.SetVideo("videos/demo.mp4", fbo);

3
src/ofApp.h

@ -7,6 +7,7 @@
#include "Yolo.h"
#include <vector>
#include "Player.h"
#include "Map.h"
class ofApp : public ofBaseApp{
@ -46,4 +47,6 @@ class ofApp : public ofBaseApp{
Emotef emo;
Yolo faceDetector;
std::vector<types::BoxfWithLandmarks> detected_faces;
Map map;
};

Loading…
Cancel
Save