ThinkSound icon indicating copy to clipboard operation
ThinkSound copied to clipboard

pandas problem

Open SoftologyPro opened this issue 1 year ago • 6 comments

I can get all the requirements installed and the UI starting. I pick a video, then click Submit and get an error. Command line shows.

Traceback (most recent call last):
  File "D:\Tests\ThinkSound\ThinkSound\extract_latents.py", line 9, in <module>
    from data_utils.v2a_utils.vggsound_224_no_audio import VGGSound
  File "D:\Tests\ThinkSound\ThinkSound\data_utils\v2a_utils\vggsound_224_no_audio.py", line 6, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Traceback (most recent call last):
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\queueing.py", line 407, in call_prediction
    output = await route_utils.call_process_api(
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\route_utils.py", line 226, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\blocks.py", line 1559, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\blocks.py", line 1447, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\video.py", line 273, in postprocess
    processed_files = (self._format_video(y), None)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\video.py", line 350, in _format_video
    video = self.make_temp_copy_if_needed(video)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\base.py", line 233, in make_temp_copy_if_needed
    temp_dir = self.hash_file(file_path)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\base.py", line 197, in hash_file
    with open(file_path, "rb") as f:
OSError: [Errno 22] Invalid argument: 'Traceback (most recent call last):\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\extract_latents.py", line 9, in <module>\n    from data_utils.v2a_utils.vggsound_224_no_audio import VGGSound\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\data_utils\\v2a_utils\\vggsound_224_no_audio.py", line 6, in <module>\n    import pandas as pd\nModuleNotFoundError: No module named \'pandas\'\n'

I try pip install pandas and run again. Same error. pip list shows pandas 2.0.2

Any idea on how to fix this one?

SoftologyPro avatar Jul 15 '25 23:07 SoftologyPro

This issue may be caused by environment confusion. While you are launching app.py from the correct environment, the script inside may call subprocess.run([python, "xxx.py", ...]), which could be using the system default Python instead of the one in your environment, leading to missing dependencies.

To resolve this, you can either:

  • Use conda to manage and activate your environment properly before running the scripts, or
  • Replace 'python' in your app.py with the full path to your desired python.exe (or Python binary), ensuring subprocesses use the correct interpreter.

Let us know if this helps!

liuhuadai avatar Jul 16 '25 02:07 liuhuadai

I only have the one version of Python installed 3.10.11. I don't use conda. This is all on Windows.

To maybe help this is the install.bat I use to install. This is run from an empty directory (with ffmpeg.exe and ffprobe.exe in there too) to install clean. I use this same/similar install process for hundreds of AI/ML systems in Visions of Chaos. None of them needed conda.

@echo off

echo *** %time% *** Deleting ThinkSound directory if it exists
if exist ThinkSound\. rd /S /Q ThinkSound

echo *** %time% *** Cloning repository
git clone https://github.com/FunAudioLLM/ThinkSound
cd ThinkSound
copy ..\ffmpeg.exe
copy ..\ffprobe.exe

echo *** %time% *** Creating venv
python -m venv venv

echo *** %time% *** Activating venv
call venv\scripts\activate.bat

echo *** %time% *** Removing flash-attn from requirements.txt
type requirements.txt | findstr /v flash-attn > stripped.txt
del requirements.txt
ren stripped.txt requirements.txt

echo *** %time% *** Removing triton from requirements.txt
type requirements.txt | findstr /v triton > stripped.txt
del requirements.txt
ren stripped.txt requirements.txt

echo *** %time% *** Installing requirements
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pandas
pip install https://huggingface.co/datasets/Softology-Pro/VoC/resolve/main/flash_attn-2.7.4.post1-cp310-cp310-win_amd64.whl
pip install triton-windows

echo *** %time% *** Installing GPU torch
pip uninstall -y torch
pip uninstall -y torch
pip install --no-cache-dir --ignore-installed --force-reinstall --no-warn-conflicts torch==2.7.0+cu128 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

echo *** %time% *** Patching numpy
pip uninstall -y numpy
pip uninstall -y numpy
pip install numpy==1.26.4

echo *** %time% *** Downloading models
git lfs install
git clone https://huggingface.co/liuhuadai/ThinkSound ckpts

call venv\scripts\deactivate.bat
cd ..
echo *** %time% *** Finished ThinkSound install
echo.
echo Check the stats for any errors.  Do not assume it worked.
pause

and then run.bat to run. It activates the venv created at install time before calling app.py.

@echo off
cd ThinkSound
call venv\scripts\activate.bat
python app.py
call venv\scripts\deactivate.bat
cd..

The UI opens fine. I can select a video, but then when I click Submit I get the pandas error.

SoftologyPro avatar Jul 16 '25 08:07 SoftologyPro

We conducted a simple test on Windows using venv and found that the subprocess calls via subprocess.Popen() (specifically line 14 and line 17 in app.py) do not use the newly created virtual environment. This explains why running app.py with venv correctly launches the Gradio interface (as that part runs directly within app.py), but errors occur when feature extraction is triggered in a subprocess.

To address this, you can replace the "python" command on lines 14 and 17 in app.py with sys.executable(without quotes) to ensure the subprocess uses the correct environment. Alternatively, if your GPU memory allows, you may use this version of app.py, which avoids subprocesses entirely—no changes to other files are needed.

lkcqswb avatar Jul 16 '25 13:07 lkcqswb

Can you give me the exact syntax change needed in app.py? The following changes both gave FileNotFoundError: [WinError 2] The system cannot find the file specified errors

        ["sys.executable", "extract_latents.py", "--duration_sec", str(duration_sec),
         "--root", videos_dir, "--tsv_path", csv_path, "--save-dir", results_dir]
        if stage == 1 else
        ["sys.executable", "predict.py", "--duration-sec", str(duration_sec),
         "--results-dir", results_dir]
        [sys.executable, "extract_latents.py", "--duration_sec", str(duration_sec),
         "--root", videos_dir, "--tsv_path", csv_path, "--save-dir", results_dir]
        if stage == 1 else
        [sys.executable, "predict.py", "--duration-sec", str(duration_sec),
         "--results-dir", results_dir]

SoftologyPro avatar Jul 16 '25 23:07 SoftologyPro

That does seem a bit unusual. You might consider trying the absolute path directly by replacing sys.executable with "D:/Tests/ThinkSound/ThinkSound/venv/Scripts/python.exe" (according to the path shown in your error message—please update it if needed) to see if that resolves the issue.

lkcqswb avatar Jul 17 '25 01:07 lkcqswb

Changing app.py lines to...

        ["D:/Tests/ThinkSound/ThinkSound/venv/Scripts/python.exe", "extract_latents.py", "--duration_sec", str(duration_sec),
         "--root", videos_dir, "--tsv_path", csv_path, "--save-dir", results_dir]
        if stage == 1 else
        ["D:/Tests/ThinkSound/ThinkSound/venv/Scripts/python.exe", "predict.py", "--duration-sec", str(duration_sec),
         "--results-dir", results_dir]

...gets past the file not found error. Now when I select a video and click submit I get this error.

start
2025-07-17 12:43:59,395 - INFO - 0 videos found in C:\Users\Jason\AppData\Local\Temp\thinksound_8ed0ff62zblqmhzp\videos
2025-07-17 12:43:59,395 - INFO - 1 videos found in C:\Users\Jason\AppData\Local\Temp\thinksound_8ed0ff62zblqmhzp\cot_coarse\cot.csv
2025-07-17 12:43:59,395 - INFO - 0 videos missing in C:\Users\Jason\AppData\Local\Temp\thinksound_8ed0ff62zblqmhzp\videos
Using a slow image processor as `use_fast` is unset and a slow processor was saved with this model. `use_fast=True` will be the default behavior in v4.52, even if the model was saved with a slow processor. This will result in minor differences in outputs. You'll still be able to use a slow processor with `use_fast=False`.
You are using the default legacy behaviour of the <class 'transformers.models.t5.tokenization_t5.T5Tokenizer'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565
2025-07-17 12:44:13,380 - INFO - Loading MotionFormer config from D:\Tests\ThinkSound\ThinkSound\data_utils\ext\synchformer\divided_224_16x4.yaml

Processing:   0%|          | 0/1 [00:00<?, ?batch/s]2025-07-17 12:44:21,272 - ERROR - Error loading video demo: Failed to intialize FFmpeg extension. Tried versions: ['6', '5', '4', '']. Enable DEBUG logging to see more details about the error.

Processing:   0%|          | 0/1 [00:07<?, ?batch/s]
Traceback (most recent call last):
  File "D:\Tests\ThinkSound\ThinkSound\extract_latents.py", line 214, in <module>
    main(args)
  File "D:\Tests\ThinkSound\ThinkSound\extract_latents.py", line 145, in main
    for i, data in enumerate(tqdm(dataloader, desc="Processing", unit="batch")):
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\tqdm\std.py", line 1181, in __iter__
    for obj in iterable:
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\dataloader.py", line 733, in __next__
    data = self._next_data()
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\dataloader.py", line 1515, in _next_data
    return self._process_data(data, worker_id)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\dataloader.py", line 1550, in _process_data
    data.reraise()
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\_utils.py", line 750, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\_utils\worker.py", line 349, in _worker_loop
    data = fetcher.fetch(index)  # type: ignore[possibly-undefined]
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 55, in fetch
    return self.collate_fn(data)
  File "D:\Tests\ThinkSound\ThinkSound\extract_latents.py", line 19, in error_avoidance_collate
    return default_collate(batch)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\_utils\collate.py", line 398, in default_collate
    return collate(batch, collate_fn_map=default_collate_fn_map)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\torch\utils\data\_utils\collate.py", line 150, in collate
    elem = batch[0]
IndexError: list index out of range

Traceback (most recent call last):
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\queueing.py", line 407, in call_prediction
    output = await route_utils.call_process_api(
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\route_utils.py", line 226, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\blocks.py", line 1559, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\blocks.py", line 1447, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\video.py", line 273, in postprocess
    processed_files = (self._format_video(y), None)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\video.py", line 350, in _format_video
    video = self.make_temp_copy_if_needed(video)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\base.py", line 233, in make_temp_copy_if_needed
    temp_dir = self.hash_file(file_path)
  File "D:\Tests\ThinkSound\ThinkSound\venv\lib\site-packages\gradio\components\base.py", line 197, in hash_file
    with open(file_path, "rb") as f:
OSError: [Errno 22] Invalid argument: '2025-07-17 12:43:59,395 - INFO - 0 videos found in C:\\Users\\Jason\\AppData\\Local\\Temp\\thinksound_8ed0ff62zblqmhzp\\videos\n2025-07-17 12:43:59,395 - INFO - 1 videos found in C:\\Users\\Jason\\AppData\\Local\\Temp\\thinksound_8ed0ff62zblqmhzp\\cot_coarse\\cot.csv\n2025-07-17 12:43:59,395 - INFO - 0 videos missing in C:\\Users\\Jason\\AppData\\Local\\Temp\\thinksound_8ed0ff62zblqmhzp\\videos\nUsing a slow image processor as `use_fast` is unset and a slow processor was saved with this model. `use_fast=True` will be the default behavior in v4.52, even if the model was saved with a slow processor. This will result in minor differences in outputs. You\'ll still be able to use a slow processor with `use_fast=False`.\nYou are using the default legacy behaviour of the <class \'transformers.models.t5.tokenization_t5.T5Tokenizer\'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565\n2025-07-17 12:44:13,380 - INFO - Loading MotionFormer config from D:\\Tests\\ThinkSound\\ThinkSound\\data_utils\\ext\\synchformer\\divided_224_16x4.yaml\n\nProcessing:   0%|          | 0/1 [00:00<?, ?batch/s]2025-07-17 12:44:21,272 - ERROR - Error loading video demo: Failed to intialize FFmpeg extension. Tried versions: [\'6\', \'5\', \'4\', \'\']. Enable DEBUG logging to see more details about the error.\n\nProcessing:   0%|          | 0/1 [00:07<?, ?batch/s]\nTraceback (most recent call last):\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\extract_latents.py", line 214, in <module>\n    main(args)\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\extract_latents.py", line 145, in main\n    for i, data in enumerate(tqdm(dataloader, desc="Processing", unit="batch")):\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\tqdm\\std.py", line 1181, in __iter__\n    for obj in iterable:\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\dataloader.py", line 733, in __next__\n    data = self._next_data()\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\dataloader.py", line 1515, in _next_data\n    return self._process_data(data, worker_id)\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\dataloader.py", line 1550, in _process_data\n    data.reraise()\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\_utils.py", line 750, in reraise\n    raise exception\nIndexError: Caught IndexError in DataLoader worker process 0.\nOriginal Traceback (most recent call last):\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\_utils\\worker.py", line 349, in _worker_loop\n    data = fetcher.fetch(index)  # type: ignore[possibly-undefined]\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\_utils\\fetch.py", line 55, in fetch\n    return self.collate_fn(data)\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\extract_latents.py", line 19, in error_avoidance_collate\n    return default_collate(batch)\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\_utils\\collate.py", line 398, in default_collate\n    return collate(batch, collate_fn_map=default_collate_fn_map)\n  File "D:\\Tests\\ThinkSound\\ThinkSound\\venv\\lib\\site-packages\\torch\\utils\\data\\_utils\\collate.py", line 150, in collate\n    elem = batch[0]\nIndexError: list index out of range\n\n'

Usually, just having ffmpeg.exe and ffprobe.exe in the same directory as the script gets ffmpeg support working, but not here?

I did try winget install --id=Gyan.FFmpeg.Shared -v "6.1.1" -e but that makes no difference. Same error.

SoftologyPro avatar Jul 17 '25 02:07 SoftologyPro