mirror of
https://github.com/opencv/opencv.git
synced 2026-07-28 06:43:01 +04:00
Merge pull request #25868 from Abdurrahheem:ash/add-gpt2-sample
Add sample for GPT2 inference #25868 ### Pull Request Readiness Checklist This PR adds sample for inferencing GPT-2 model. More specificly implementation of GPT-2 from [this repository](https://github.com/karpathy/build-nanogpt). Currently inference in OpenCV is only possible to do with fixed window size due to not supported dynamic shapes. See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
060c24bec9
commit
88f05e49be
@@ -108,3 +108,21 @@ void Copy_vector_string_to_List(JNIEnv* env, std::vector<std::string>& vs, jobje
|
||||
env->DeleteLocalRef(element);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
void Copy_vector_MatShape_to_List(JNIEnv* env, std::vector<cv::dnn::MatShape>& vs, jobject list)
|
||||
{
|
||||
static jclass juArrayList = ARRAYLIST(env);
|
||||
jmethodID m_clear = LIST_CLEAR(env, juArrayList);
|
||||
jmethodID m_add = LIST_ADD(env, juArrayList);
|
||||
|
||||
env->CallVoidMethod(list, m_clear);
|
||||
for (size_t i = 0; i < vs.size(); i++)
|
||||
{
|
||||
jintArray element = env->NewIntArray((jint)vs[i].size());
|
||||
env->SetIntArrayRegion(element, 0, (jint)vs[i].size(), (const jint*)&vs[i][0]);
|
||||
env->CallBooleanMethod(list, m_add, element);
|
||||
env->DeleteLocalRef(element);
|
||||
}
|
||||
}
|
||||
#endif // HAVE_OPENCV_DNN
|
||||
|
||||
@@ -23,4 +23,11 @@ std::vector<std::string> List_to_vector_string(JNIEnv* env, jobject list);
|
||||
|
||||
void Copy_vector_string_to_List(JNIEnv* env, std::vector<std::string>& vs, jobject list);
|
||||
|
||||
#endif /* LISTCONVERTERS_HPP */
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include "opencv2/dnn.hpp"
|
||||
|
||||
void Copy_vector_MatShape_to_List(JNIEnv* env, std::vector<cv::dnn::MatShape>& vs, jobject list);
|
||||
|
||||
#endif // HAVE_OPENCV_DNN
|
||||
|
||||
#endif /* LISTCONVERTERS_HPP */
|
||||
|
||||
Reference in New Issue
Block a user