Skip to content

Commit

Permalink
add ax650 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHEQIUSHUI committed Aug 15, 2023
1 parent ebb9fc3 commit c7157c6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# CLIP-ONNX
# CLIP

## ONNX

```
./main -e ../onnx_models/CLIP_encoder.onnx -d ../onnx_models/decode.onnx -v ../vocab.txt -i ../images/ -t ../text.txt
inputs:
input.1: 1 x 3 x 224 x 224
output:
2270: 1 x 512
per image:
image path\text| bird| cat| dog|
../images/bird.jpg| 1.00| 0.00| 0.00|
../images/cat.jpg| 0.00| 0.99| 0.01|
../images/dog-chai.jpeg| 0.00| 0.02| 0.98|
per text:
text\image path| ../images/bird.jpg| ../images/cat.jpg| ../images/dog-chai.jpeg|
bird| 0.96| 0.01| 0.03|
cat| 0.00| 0.91| 0.09|
dog| 0.00| 0.00| 1.00|
```

# AX650

```
/opt/test/clip # ./main -e compiled.axmodel -d onnx_models/decode.onnx -v vocab.
txt -i images/ -t text.txt
Engine creating handle is done.
Engine creating context is done.
Engine get io info is done.
Engine alloc io is done.
[I][ init][ 275]: RGB MODEL
per image:
image path\text| bird| cat| dog|
images/bird.jpg| 1.00| 0.00| 0.00|
images/cat.jpg| 0.01| 0.98| 0.01|
images/dog-chai.jpeg| 0.00| 0.00| 1.00|
per text:
text\image path| images/bird.jpg| images/cat.jpg| images/dog-chai.jpeg|
bird| 1.00| 0.00| 0.00|
cat| 0.00| 0.99| 0.01|
dog| 0.00| 0.00| 1.00|
```
File renamed without changes
1 change: 1 addition & 0 deletions src/Runner/CLIPAX650.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CLIPAX650 : public CLIP
return;
}
cv::resize(image, input, cv::Size(224, 224));
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);
auto ret = m_encoder->inference();

image_features.resize(LEN_IMAGE_FEATURE);
Expand Down
1 change: 1 addition & 0 deletions src/Runner/CLIPOnnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CLIPOnnx : public CLIP
return;
}
cv::resize(image, input, cv::Size(224, 224));
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);

float *inputPtr = (float *)m_encoder->getInputPtr(0);

Expand Down
28 changes: 16 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,27 @@ int main(int argc, char *argv[])
mClip->decode(image_features, text_features, logits_per_image, logits_per_text);

printf("\n");
printf("per image:\n");
printf("%32s|", "image path\\text");
for (size_t i = 0; i < texts.size(); i++)
if (texts.size() > 1)
{
printf("%32s|", texts[i].c_str());
}
printf("\n");
for (size_t i = 0; i < logits_per_image.size(); i++)
{
printf("%32s|", image_paths[i].c_str());
for (size_t j = 0; j < logits_per_image[i].size(); j++)
printf("per image:\n");
printf("%32s|", "image path\\text");
for (size_t i = 0; i < texts.size(); i++)
{
printf("%32.2f|", logits_per_image[i][j]);
printf("%32s|", texts[i].c_str());
}
printf("\n");
for (size_t i = 0; i < logits_per_image.size(); i++)
{
printf("%32s|", image_paths[i].c_str());
for (size_t j = 0; j < logits_per_image[i].size(); j++)
{
printf("%32.2f|", logits_per_image[i][j]);
}
printf("\n");
}
printf("\n");
}
printf("\n");

printf("\n");
printf("per text:\n");
printf("%32s|", "text\\image path");
Expand Down
4 changes: 2 additions & 2 deletions text.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bird
cat
dog
brid
dog

0 comments on commit c7157c6

Please sign in to comment.