File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1515 }
1616
1717 NSString *pathString = [NSString stringWithUTF8String: model_path];
18+
19+ // Check if file exists
20+ NSFileManager *fileManager = [NSFileManager defaultManager ];
21+ if (![fileManager fileExistsAtPath: pathString]) {
22+ NSLog (@" Error: ANE model file does not exist at path: %@ " , pathString);
23+ return nullptr ;
24+ }
25+
26+ // Check if it's a directory (for .mlmodelc packages)
27+ BOOL isDirectory;
28+ if ([fileManager fileExistsAtPath: pathString isDirectory: &isDirectory]) {
29+ if (!isDirectory && ![pathString hasSuffix: @" .mlmodelc" ]) {
30+ NSLog (@" Warning: ANE model path should typically be a .mlmodelc directory: %@ " , pathString);
31+ }
32+ }
33+
1834 NSURL *modelURL = [NSURL fileURLWithPath: pathString];
1935
2036 NSLog (@" Loading ANE model from: %@ " , modelURL.absoluteString);
3248 return nullptr ;
3349 }
3450
51+ NSLog (@" Successfully loaded ANE model from: %@ " , pathString);
3552 return model;
3653}
3754
Original file line number Diff line number Diff line change 1010#include < cstdio>
1111#include < cstdlib>
1212#include < cstring>
13+ #include < fstream>
1314#include < limits>
1415#include < vector>
1516
@@ -159,7 +160,15 @@ struct mtmd_context {
159160
160161 // Set ANE model path for iOS
161162 if (ctx_params.ane_model_path && ctx_v) {
163+ // Check if ANE model file exists
164+ std::ifstream ane_file (ctx_params.ane_model_path );
165+ if (!ane_file.good ()) {
166+ throw std::runtime_error (string_format (" ANE model file does not exist: %s" , ctx_params.ane_model_path ));
167+ }
168+ ane_file.close ();
169+
162170 clip_set_ane_model_path (ctx_v, ctx_params.ane_model_path );
171+ LOG_INF (" ANE model path set to: %s\n " , ctx_params.ane_model_path );
163172 }
164173 if (!ctx_v && !ctx_a) {
165174 throw std::runtime_error (string_format (" Failed to load CLIP model from %s\n " , mmproj_fname));
You can’t perform that action at this time.
0 commit comments