-
I noticed dlib has a I've been using this approach for some time, but I wonder if there is a simpler way? using namespace dlib;
auto project(const std::vector<matrix<float, 0, 1>>& embeddings, const size_t output_dims) -> std::vector<matrix<float, 0, 1>>
{
vector_normalizer_pca<matrix<float, 0, 1>> normalizer;
const matrix<float, 0, 0> pca = normalizer.pca_matrix();
normalizer.train(embeddings, 1);
const auto& m = normalizer.means();
const auto& s = normalizer.std_devs();
const matrix<float, 0, 0> M = rowm(pca, range(0, output_dims - 1));
std::vector<matrix<float, 0, 1>> projected;
for (size_t i = 0; i < embeddings.size(); ++i)
{
projected.push_back(M * pointwise_multiply(embeddings[i] - m, s));
}
return projected;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You have
backwards, but yeah that's all there is in dlib. In the past whenever I was doing this stuff it was at work and just kinda different each time. Depends on the context. Like often you just call svd() directly. |
Beta Was this translation helpful? Give feedback.
You have
backwards, but yeah that's all there is in dlib. In the past whenever I was doing this stuff it was at work and just kinda different each time. Depends on the context. Like often you just call svd() directly.