cosmos icon indicating copy to clipboard operation
cosmos copied to clipboard

Model not able to detect physical-plausibility

Open Akshaysharma29 opened this issue 5 months ago • 3 comments

Hi Team, wonderful work. I have been trying to detect physical-plausibility in AI generated video but it is not able to detect that it giving approval to almost all videos. I have also tried the sample prompt from the cookbook but the results are the same. Below is the code.

# python3 check_physics_cosmos_folder.py /path/to/folder
# Results are saved to /path/to/folder/physics_results.txt

# python3 check_physics_cosmos_folder.py  /home/akshay_sharma_jiostar_com/akshay_venv/creators/physics/no_issue
# python3 check_physics_cosmos_folder.py  /home/akshay_sharma_jiostar_com/akshay_venv/creators/physics/issue
# python3 check_physics_cosmos_folder.py  /home/akshay_sharma_jiostar_com/akshay_venv/creators/physics/realistic_video


import base64
import requests
import sys
import os
from pathlib import Path
from datetime import datetime

VIDEO_EXTENSIONS = {".mp4", ".mov", ".avi", ".mkv", ".webm"}

def encode_video(video_path: str) -> str:
    with open(video_path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

def check_physics(video_path: str, endpoint: str = "http://localhost:8001"):
    video_b64 = encode_video(video_path)

    payload = {
        # "model": "Cosmos3-Nano",
        "model": "Cosmos3-Super",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "video_url",
                        "video_url": {
                            "url": f"data:video/mp4;base64,{video_b64}"
                        }
                    },
                    {
                        "type": "text",
                        "text": (
                            '''Is this video physically plausible/possible according to your understanding of e.g. object permanence, shape constancy (objects maintain shape over time), continuous trajectories of objects? Assume it is the normal laws of physics.
Your answer should be based on the events in the video and ignore the quality of the simulation engine.
(A) Possible
(B) Impossible'''
                        )
                    }
                ]
            }
        ],
        "max_tokens": 4096,
        "fps": 4, 
        "do_sample_frames": True
        # "temperature": 0.1
        # ✅ Reasoning mode sampling params
        # "enable_sound": False,
        # "max_new_tokens": 4096,
        # "do_sample": True,
        # "temperature": 0.6,
        # "top_p": 0.95,
        # "top_k": 20,
        # "repetition_penalty": 1.0,
        # "presence_penalty": 0.0,
    }

    response = requests.post(
        f"{endpoint}/v1/chat/completions",
        headers={"Content-Type": "application/json"},
        json=payload,
        timeout=120
    )
    response.raise_for_status()
    return response.json()["choices"][0]["message"]["content"]


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python3 check_physics_cosmos_folder.py <folder_path>")
        sys.exit(1)

    folder = Path(sys.argv[1])
    if not folder.is_dir():
        print(f"Error: {folder} is not a directory")
        sys.exit(1)

    videos = sorted([f for f in folder.iterdir() if f.suffix.lower() in VIDEO_EXTENSIONS])
    if not videos:
        print(f"No video files found in {folder}")
        sys.exit(1)

    output_file = folder / "physics_results.txt"
    print(f"Found {len(videos)} video(s). Results will be saved to {output_file}\n")

    with open(output_file, "w") as out:
        out.write(f"Physics Analysis Results\n")
        out.write(f"Run: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
        out.write(f"Folder: {folder.resolve()}\n")
        out.write("=" * 60 + "\n\n")

        for i, video in enumerate(videos, 1):
            print(f"[{i}/{len(videos)}] Analyzing: {video.name}")
            out.write(f"File: {video.name}\n")
            out.write("-" * 40 + "\n")
            try:
                result = check_physics(str(video))
                print(result)
                out.write(result + "\n")
            except Exception as e:
                err = f"ERROR: {e}"
                print(err)
                out.write(err + "\n")
            out.write("\n" + "=" * 60 + "\n\n")
            out.flush()

    print(f"\nDone. Results saved to {output_file}")

Can you help me with this? Thanks

Akshaysharma29 avatar Jun 05 '26 06:06 Akshaysharma29

Thanks for trying it out @Akshaysharma29 . Would you share some testing videos so we can test them on our end?

tylin avatar Jun 05 '26 18:06 tylin

Hi @tylin it is internal data which I can share. I have tried one open video just for example. Here it is(it is very blurry). I am not sure whether it can help you to find out reason. Will check for more AI generated examples.

https://github.com/user-attachments/assets/78dbcc09-9428-46e8-9d8e-8dd791d1c7df

Akshaysharma29 avatar Jun 08 '26 06:06 Akshaysharma29

Quick heads-up: this path is actually Cosmos3-Reasoner (the VLM) over /v1/chat/completions, which runs on plain vLLM rather than the Omni generation pipeline — so it's more of a prompting/sampling thing than a serving bug.

Couple of usual suspects for "says Possible to everything": with fps: 4 + do_sample_frames on a short clip you might only be feeding it a handful of frames, so it barely sees the motion that breaks physics — try bumping the frame count. And a flat A/B choice tends to bias toward "Possible"; having it reason before answering usually helps a lot. If you can drop a couple of the clips here (like @tylin asked), happy to repro on our end.

david6666666 avatar Jun 09 '26 16:06 david6666666