Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

测试公式

\[ E=mc^2 \]

\[ \sigma(z_i) = \frac{e^{z_{i}}}{\sum_{j=1}^K e^{z_{j}}} \ \ \ for\ i=1,2,\dots,K \]

\[ L_{\delta}= \left\{\begin{matrix} \frac{1}{2}(y - \hat{y})^{2} & if \left | (y - \hat{y}) \right | < \delta\\ \delta ((y - \hat{y}) - \frac1 2 \delta) & otherwise \end{matrix}\right. \]

\[ \epsilon \sim \mathcal{N}(0, \textbf{I}) \]

\[ \vec{z} \sim \mathcal{N}(\vec{\mu}, \sigma^2 \textbf{I}) \]

\[ \sum_{i=1}^{D}|x_i-y_i| \]

\[ Accuracy = \frac{TP+TN}{TP+TN+FP+FN} \]

\[ Precision = \frac{TP}{TP+FP} \]

\[ Recall = \frac{TP}{TP+FN} \]

\[ F1 = \frac{2*Precision*Recall}{Precision+Recall} = \frac{2*TP}{2*TP+FP+FN} \]

测试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import net
import torch
import os
from face_alignment import align
import numpy as np


adaface_models = {
'ir_50':"pretrained/adaface_ir50_ms1mv2.ckpt",
}

def load_pretrained_model(architecture='ir_50'):
# load model and pretrained statedict
assert architecture in adaface_models.keys()
model = net.build_model(architecture)
statedict = torch.load(adaface_models[architecture])['state_dict']
model_statedict = {key[6:]:val for key, val in statedict.items() if key.startswith('model.')}
model.load_state_dict(model_statedict)
model.eval()
return model

def to_input(pil_rgb_image):
np_img = np.array(pil_rgb_image)
brg_img = ((np_img[:,:,::-1] / 255.) - 0.5) / 0.5
tensor = torch.tensor([brg_img.transpose(2,0,1)]).float()
return tensor

if __name__ == '__main__':

model = load_pretrained_model('ir_50')
feature, norm = model(torch.randn(2,3,112,112))

test_image_path = 'face_alignment/test_images'
features = []
for fname in sorted(os.listdir(test_image_path)):
path = os.path.join(test_image_path, fname)
aligned_rgb_img = align.get_aligned_face(path)
bgr_tensor_input = to_input(aligned_rgb_img)
feature, _ = model(bgr_tensor_input)
features.append(feature)

similarity_scores = torch.cat(features) @ torch.cat(features).T
print(similarity_scores)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode() : val(0), left(nullptr), right(nullptr) {}
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution
{
public:
vector<int> inorderTraversal(TreeNode *root)
{
vector<int> res;
stack<TreeNode *> s;
TreeNode *p = root;
while (p || !s.empty())
{
if (p)
{
s.push(p);
p = p->left;
}
else
{
TreeNode *temp = s.top();
s.pop();
res.push_back(temp->val);
p = temp->right;
}
}
return res;
}
};

class Solution2
{
public:
vector<int> inorderTraversal(TreeNode *root)
{
vector<int> res;
stack<TreeNode *> s;
TreeNode *p = root;
while (p || !s.empty())
{
while (p)
{
s.push(p);
p = p->left;
}
TreeNode *temp = s.top();
s.pop();
res.push_back(temp->val);
p = temp->right;
}
return res;
}
};

int main()
{

return 0;
}

Hello World
https://arcsin2.cloud/2023/02/18/hello-world/
作者
arcsin2
发布于
2023年2月18日
许可协议