Handle cases where image file does not exist
This commit is contained in:
parent
ae01c859e5
commit
5009ae90ef
1 changed files with 13 additions and 3 deletions
|
@ -35,15 +35,25 @@ int main(int argc, char ** argv) {
|
||||||
// load and preprocess the image
|
// load and preprocess the image
|
||||||
clip_image_u8 img;
|
clip_image_u8 img;
|
||||||
clip_image_f32 img_res;
|
clip_image_f32 img_res;
|
||||||
clip_image_load_from_file(img_path, &img);
|
if (!clip_image_load_from_file(img_path, &img)) {
|
||||||
|
fprintf(stderr, "%s: is %s really an image file?\n", __func__, img_path);
|
||||||
|
|
||||||
clip_image_preprocess(ctx_clip, &img, &img_res, /*pad2square =*/ true);
|
clip_free(ctx_clip);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clip_image_preprocess(ctx_clip, &img, &img_res, /*pad2square =*/ true)) {
|
||||||
|
fprintf(stderr, "%s: unable to preprocess %s\n", __func__, img_path);
|
||||||
|
|
||||||
|
clip_free(ctx_clip);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int n_img_pos = clip_n_pos(ctx_clip);
|
int n_img_pos = clip_n_pos(ctx_clip);
|
||||||
float * image_embd = (float *)malloc(clip_embd_nbytes(ctx_clip));
|
float * image_embd = (float *)malloc(clip_embd_nbytes(ctx_clip));
|
||||||
|
|
||||||
if (!image_embd) {
|
if (!image_embd) {
|
||||||
fprintf(stderr, "Unable to allocate memory for CLIP embeddings\n");
|
fprintf(stderr, "Unable to allocate memory for image embeddings\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue