Skip to content

(Possible) Incorrect assignment of image mean/std values in clip_model_load() #99

Open
@tino926

Description

@tino926

The current implementation of clip_model_load() seems incorrectly assigns mean and standard deviation values to the image_mean and image_std fields.

The existing code fetches data for all three color channels (presumably RGB) but fails to iterate through the retrieved arrays. This results in all channels being assigned the first value of the respective image_mean and image_std arrays.

The original code is as this:

    int idx_mean = get_key_idx(ctx, KEY_IMAGE_MEAN);
    int idx_std = get_key_idx(ctx, KEY_IMAGE_STD);
    for (int i = 0; i < 3; ++i) {
        new_clip->image_mean[i] = *((float *)gguf_get_arr_data(ctx, idx_mean));
        new_clip->image_std[i] = *((float *)gguf_get_arr_data(ctx, idx_std));
    }

To rectify this, the code should access the correct index within the retrieved arrays for each color channel, as shown below:

    int idx_mean = get_key_idx(ctx, KEY_IMAGE_MEAN);
    int idx_std = get_key_idx(ctx, KEY_IMAGE_STD);
    for (int i = 0; i < 3; ++i) {
        new_clip->image_mean[i] = *(((float *)gguf_get_arr_data(ctx, idx_mean)) + i);
        new_clip->image_std[i] = *(((float *)gguf_get_arr_data(ctx, idx_std)) + i);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions