Initial commit: scene-actor-extraction pipeline
Source (KPN++ pipeline nodes, ArcFace embedders, SCRFD/YuNet detectors, gallery builder), build scripts, and eval artifacts. - external/KPN as a git submodule (gitea.tourolle.paris/dtourolle/KPN) - ONNX models tracked via Git LFS (models/*.onnx) - generated outputs, TensorRT engines, reference repos, and media ignored
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "gallery_store.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ActorGallery load_gallery(const std::string& path) {
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open())
|
||||
throw std::runtime_error("load_gallery: cannot open " + path);
|
||||
|
||||
json j;
|
||||
f >> j;
|
||||
|
||||
ActorGallery gallery;
|
||||
for (const auto& ja : j.at("actors")) {
|
||||
ActorGallery::Actor actor;
|
||||
actor.imdb_id = ja.at("imdb_id").get<std::string>();
|
||||
actor.name = ja.at("name").get<std::string>();
|
||||
|
||||
if (ja.contains("source_images"))
|
||||
actor.source_images = ja.at("source_images").get<std::vector<std::string>>();
|
||||
|
||||
for (const auto& je : ja.at("embeddings")) {
|
||||
Embedding emb = je.get<Embedding>();
|
||||
actor.embeddings.push_back(emb);
|
||||
}
|
||||
|
||||
gallery.actors.push_back(std::move(actor));
|
||||
}
|
||||
return gallery;
|
||||
}
|
||||
|
||||
void save_gallery(const std::string& path, const ActorGallery& gallery) {
|
||||
json j;
|
||||
j["actors"] = json::array();
|
||||
|
||||
for (const auto& actor : gallery.actors) {
|
||||
json ja;
|
||||
ja["imdb_id"] = actor.imdb_id;
|
||||
ja["name"] = actor.name;
|
||||
ja["source_images"] = actor.source_images;
|
||||
|
||||
ja["embeddings"] = json::array();
|
||||
for (const auto& emb : actor.embeddings) {
|
||||
ja["embeddings"].push_back(
|
||||
std::vector<float>(emb.begin(), emb.end()));
|
||||
}
|
||||
j["actors"].push_back(std::move(ja));
|
||||
}
|
||||
|
||||
std::ofstream f(path);
|
||||
if (!f.is_open())
|
||||
throw std::runtime_error("save_gallery: cannot write " + path);
|
||||
f << j.dump(2) << "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user