Skip to content

Commit

Permalink
Merge pull request #2 from ZHEQIUSHUI/auto_size
Browse files Browse the repository at this point in the history
auto input size
  • Loading branch information
ZHEQIUSHUI authored Oct 30, 2023
2 parents f57eb93 + 1e0a45b commit 9663e11
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 9 additions & 1 deletion qtproj/CLIPQT/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>CLIP</string>
</property>
<property name="styleSheet">
<string notr="true"/>
Expand All @@ -38,13 +38,21 @@
<height>40</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">border-radius: 20px;
background-color: rgb(99, 122, 125);</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>Type in Chinese or English and click Enter to search.</string>
</property>
</widget>
</item>
<item>
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/CLIP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CLIP
int LEN_IMAGE_FEATURE = 512;
int LEN_TEXT_FEATURE = 512;
int LEN_TEXT_TOKEN = 77;

int input_height, input_width;
public:
CLIP()
{
Expand Down
7 changes: 5 additions & 2 deletions src/Runner/CLIPAX650.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class CLIPAX650 : public CLIP
{
m_encoder.reset(new ax_runner_ax650);
m_encoder->init(encoder_path.c_str());
input = cv::Mat(224, 224, CV_8UC3, m_encoder->get_input(0).pVirAddr);
input_height = m_encoder->get_algo_height();
input_width = m_encoder->get_algo_width();
ALOGI("input size %d %d", input_height, input_width);
input = cv::Mat(input_height, input_width, CV_8UC3, m_encoder->get_input(0).pVirAddr);

LEN_IMAGE_FEATURE = m_encoder->get_output(0).vShape[1];
ALOGI("image feature len %d", LEN_IMAGE_FEATURE);
Expand All @@ -27,7 +30,7 @@ class CLIPAX650 : public CLIP
ALOGE("encoder not init");
return;
}
cv::resize(image, input, cv::Size(224, 224));
cv::resize(image, input, cv::Size(input_width, input_height));
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);
auto ret = m_encoder->inference();

Expand Down
11 changes: 8 additions & 3 deletions src/Runner/CLIPOnnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class CLIPOnnx : public CLIP
config.nthread = 8;
config.onnx_model = encoder_path;
m_encoder->load(config);

input_width = m_encoder->getInputShape(0)[3];
input_height = m_encoder->getInputShape(0)[2];
ALOGI("input size %d %d", input_height, input_width);

LEN_IMAGE_FEATURE = m_encoder->getOutputShape(0)[1];
ALOGI("image feature len %d", LEN_IMAGE_FEATURE);
image_features_input = std::vector<float>(1024 * LEN_IMAGE_FEATURE);
Expand All @@ -28,15 +33,15 @@ class CLIPOnnx : public CLIP
ALOGE("encoder not init");
return;
}
cv::resize(image, input, cv::Size(224, 224));
cv::resize(image, input, cv::Size(input_width, input_height));
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);

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

uchar *img_data = input.data;

int letterbox_cols = 224;
int letterbox_rows = 224;
int letterbox_cols = input_width;
int letterbox_rows = input_height;
for (int c = 0; c < 3; c++)
{
for (int h = 0; h < letterbox_rows; h++)
Expand Down

0 comments on commit 9663e11

Please sign in to comment.