@@ -157,15 +157,19 @@ static bool load_labels(const char * filename, std::vector<std::string> & labels
157157 return true ;
158158}
159159
160- static bool load_labels_gguf (const struct gguf_context * ctx , const char * filename, std::vector<std::string> & labels)
160+ static bool load_labels_gguf (struct ggml_context * ctx, const struct gguf_context * ctx_gguf , const char * filename, std::vector<std::string> & labels)
161161{
162- int tensor = gguf_find_tensor (ctx, filename);
163- if (tensor == - 1 ) {
162+ struct ggml_tensor * tensor = ggml_get_tensor (ctx, filename);
163+ if (tensor == NULL ) {
164164 return false ;
165165 }
166- const size_t offset = gguf_get_tensor_offset (ctx, tensor);
167- const size_t len = gguf_get_tensor_size (ctx, tensor);
168- const char * data = (char *)gguf_get_data (ctx);
166+ int tensoridx = gguf_find_tensor (ctx_gguf, filename);
167+ if (tensoridx == -1 ) {
168+ return false ;
169+ }
170+ const size_t len = ggml_nelements (tensor);
171+ const size_t offset = gguf_get_tensor_offset (ctx_gguf, tensoridx);
172+ const char * data = (char *)gguf_get_data (ctx_gguf);
169173 membuf buf (data + offset, data + offset + len);
170174 std::istream file_in (&buf);
171175 if (!file_in) {
@@ -195,21 +199,26 @@ static bool load_alphabet(std::vector<yolo_image> & alphabet)
195199 return true ;
196200}
197201
198- static bool load_alphabet_gguf (const struct gguf_context * ctx , std::vector<yolo_image> & alphabet)
202+ static bool load_alphabet_gguf (struct ggml_context * ctx, const struct gguf_context * ctx_gguf , std::vector<yolo_image> & alphabet)
199203{
200204 alphabet.resize (8 * 128 );
201205 for (int j = 0 ; j < 8 ; j++) {
202206 for (int i = 32 ; i < 127 ; i++) {
203207 char fname[256 ];
204208 sprintf (fname, " data/labels/%d_%d.png" , i, j);
205- int tensor = gguf_find_tensor (ctx, fname);
206- if (tensor == -1 ) {
209+ struct ggml_tensor * tensor = ggml_get_tensor (ctx, fname);
210+ if (tensor == NULL ) {
211+ fprintf (stderr, " Cannot find '%s' in tensor\n " , fname);
212+ return false ;
213+ }
214+ int tensoridx = gguf_find_tensor (ctx_gguf, fname);
215+ if (tensoridx == -1 ) {
207216 fprintf (stderr, " Cannot find '%s' in tensor\n " , fname);
208217 return false ;
209218 }
210- const size_t offset = gguf_get_tensor_offset (ctx, tensor);
211- const size_t len = gguf_get_tensor_size (ctx, tensor );
212- const char * data = (char *)gguf_get_data (ctx );
219+ const size_t len = ggml_nelements ( tensor);
220+ const size_t offset = gguf_get_tensor_offset (ctx_gguf, tensoridx );
221+ const char * data = (char *)gguf_get_data (ctx_gguf );
213222 if (!load_image_from_memory (data + offset, len, alphabet[j*128 + i])) {
214223 fprintf (stderr, " Cannot load '%s'\n " , fname);
215224 return false ;
@@ -592,15 +601,15 @@ int main(int argc, char *argv[])
592601 return 1 ;
593602 }
594603 std::vector<std::string> labels;
595- if (!load_labels_gguf (model.ctx_gguf , " data/coco.names" , labels)) {
604+ if (!load_labels_gguf (model.ctx , model. ctx_gguf , " data/coco.names" , labels)) {
596605 fprintf (stderr, " %s: skipped loading labels from 'data/coco.names' in model\n " , __func__);
597606 if (!load_labels (" data/coco.names" , labels)) {
598607 fprintf (stderr, " %s: failed to load labels from 'data/coco.names'\n " , __func__);
599608 return 1 ;
600609 }
601610 }
602611 std::vector<yolo_image> alphabet;
603- if (!load_alphabet_gguf (model.ctx_gguf , alphabet)) {
612+ if (!load_alphabet_gguf (model.ctx , model. ctx_gguf , alphabet)) {
604613 fprintf (stderr, " %s: skipped loading alphabet from model\n " , __func__);
605614 if (!load_alphabet (alphabet)) {
606615 fprintf (stderr, " %s: failed to load alphabet\n " , __func__);
0 commit comments