[Python] Mismatched number of tokens and features: LLaVA

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    model_id = "llava-hf/llava-1.5-7b-hf"
    pipe = pipeline("image-to-text",
    model=model_id,
    model_kwargs={})

    def test_single_image():
    """
    Test the model with a single image from the dataset.
    """
    # Load just one image
    images_data = load_test_images(num_images=1)

    if not images_data:
    print("No images found in the dataset")
    return

    # Get the first image
    image_data = images_data[0]
    print(f"Testing with image {image_data['index']}")
    print(f"URL: {image_data['image_url']}")
    print("\nOriginal hierarchical caption:")
    print(image_data['hierarchical_caption'])

    # Download and process the image
    image = get_image_from_url(image_data['image_url'])
    if image is None:
    print("Failed to download image")
    return

    print("\nGenerating caption...")
    generated_caption = generate_hierarchical_caption(image, pipe)

    if generated_caption is None:
    print("Failed to generate caption")
    return

    print("\nGenerated hierarchical caption:")
    print(generated_caption)
    print("\nComparison:")
    print("-" * 80)
    print("Original:", image_data['hierarchical_caption'])
    print("Generated:", generated_caption)


    The exception:

    ValueError: Image features and image tokens do not match: tokens: 1, features 576


    I keep getting this error. Please help! Not sure what to do. I've been trying to generate a caption but keep running into this error. Has anyone else seen this error? Any ideas of what to do? I greatly appreciate it.

    Continue reading...

Compartilhe esta Página