roboflow / notebooks

Examples and tutorials on using SOTA computer vision models and techniques. Learn everything from old-school ResNet, through YOLO and object-detection transformers like DETR, to the latest models like Grounding DINO and SAM.
https://roboflow.com/models
4.89k stars 759 forks source link

Issue with load_model on Windows platform #97

Open Roman-Rudensky opened 1 year ago

Roman-Rudensky commented 1 year ago

Search before asking

Notebook name

zero-shot-object-detection-with-grounding-dino.ipynb

Bug

image

Environment

Minimal Reproducible Example

No response

Additional

The issue happens because shutil.copyfile() attempts to open tempfile which is already opened. On Windows platform this raises Permission Error. Here's how I could solve that in slconfig.py (lines 80-83): 80 with tempfile.TemporaryDirectory() as temp_config_dir: 81 temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix=".py") # here temp_config_file is opened 82 temp_config_name = osp.basename(temp_config_file.name)

on Windows attempt to open temp_config_file by shutil raises IOError: [Errno 13] Permission denied:

               # close file before using shutil
                temp_config_file.close()

83 shutil.copyfile(filename, osp.join(temp_config_dir, temp_config_name))

Are you willing to submit a PR?

github-actions[bot] commented 1 year ago

πŸ‘‹ Hello @Roman-Rudensky, thank you for leaving an issue on Roboflow Notebooks.

🐞 Bug reports

If you are filing a bug report, please be as detailed as possible. This will help us more easily diagnose and resolve the problem you are facing. To learn more about contributing, check out our Contributing Guidelines.

If you require support with custom code that is not part of Roboflow Notebooks, please reach out on the Roboflow Forum or on the GitHub Discussions page associated with this repository.

πŸ’¬ Get in touch

Do you have more questions about Roboflow that we haven't responded to yet? Feel free to ask them on the Roboflow Discuss forum. Our developer advocates and community team actively respond to questions there.

To ask questions about Notebooks, head over to the GitHub Discussions section of this repository.

tzjtatata commented 1 year ago

The bug is caused by different implement of tempfile between linux and windows. The file is already opened but shutil.copyfile() will try to open it again causing the permission error -- the file is already locked. So you should use delete=False when using NamedTemporaryFile near slconfig.py:86, and mannually close the tempfile near the code 'tempfile.close()' with os.unlink(...). ref: https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file

jacobpchen commented 10 months ago

Leaving this here for others, I went to the slconfig.py file (located in GroundingDino/groundingdino/util/slconfig.py

and added delete=False to line 81

The line now reads: temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix=".py", delete=False)