Update llava-cli.cpp
Change functions to use image as a vector datatype
This commit is contained in:
parent
124e259dc6
commit
8c0a5b0e1e
1 changed files with 6 additions and 17 deletions
|
@ -116,7 +116,7 @@ static void show_additional_info(int /*argc*/, char ** argv) {
|
||||||
fprintf(stderr, " note: a lower temperature value like 0.1 is recommended for better quality.\n");
|
fprintf(stderr, " note: a lower temperature value like 0.1 is recommended for better quality.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct llava_image_embed * load_image(llava_context * ctx_llava, gpt_params * params) {
|
static struct llava_image_embed * load_image(llava_context * ctx_llava, gpt_params * params, std::string * image) {
|
||||||
|
|
||||||
// load and preprocess the image
|
// load and preprocess the image
|
||||||
llava_image_embed * embed = NULL;
|
llava_image_embed * embed = NULL;
|
||||||
|
@ -132,9 +132,9 @@ static struct llava_image_embed * load_image(llava_context * ctx_llava, gpt_para
|
||||||
}
|
}
|
||||||
params->prompt = remove_image_from_prompt(prompt);
|
params->prompt = remove_image_from_prompt(prompt);
|
||||||
} else {
|
} else {
|
||||||
embed = llava_image_embed_make_with_filename(ctx_llava->ctx_clip, params->n_threads, params->image.c_str());
|
embed = llava_image_embed_make_with_filename(ctx_llava->ctx_clip, params->n_threads, image.c_str());
|
||||||
if (!embed) {
|
if (!embed) {
|
||||||
fprintf(stderr, "%s: is %s really an image file?\n", __func__, params->image.c_str());
|
fprintf(stderr, "%s: is %s really an image file?\n", __func__, image.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,24 +281,13 @@ int main(int argc, char ** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss(params.image);
|
for (auto & image : image) {
|
||||||
std::vector<std::string> imagestack;
|
|
||||||
|
|
||||||
while( ss.good() )
|
|
||||||
{
|
|
||||||
std::string substr;
|
|
||||||
getline( ss, substr, ',' );
|
|
||||||
imagestack.push_back( substr );
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto & image : imagestack) {
|
|
||||||
|
|
||||||
auto ctx_llava = llava_init_context(¶ms, model);
|
auto ctx_llava = llava_init_context(¶ms, model);
|
||||||
params.image=image;
|
|
||||||
|
|
||||||
auto image_embed = load_image(ctx_llava, ¶ms);
|
auto image_embed = load_image(ctx_llava, ¶ms, &image);
|
||||||
if (!image_embed) {
|
if (!image_embed) {
|
||||||
std::cerr << "error: failed to load image " << params.image << ". Terminating\n\n";
|
std::cerr << "error: failed to load image " << image << ". Terminating\n\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue