简体   繁体   English

创建一个BAT文件以循环通过整个文件夹运行python脚本

[英]Creating a BAT file for loop running python script through whole folder

The thing is right now I have a visualization python script. 现在,我有了一个可视化的python脚本。 If I run it on CUDA mode, I always get the error message of: RuntimeError: CUDA error: out of memory (on both CUDA mode for single image visualization and folder visualization). 如果我在CUDA模式下运行它,则总是收到以下错误消息: RuntimeError: CUDA error: out of memory (在用于单个图像可视化和文件夹可视化的CUDA模式下)。 However, when I run the script on CPU mode, my CPU stands and it takes like 30seconds to run through one image visualization. 但是,当我在CPU模式下运行脚本时,我的CPU处于站立状态,并且需要30秒才能完成一次图像可视化。

But when I try to have a for loop inside the python script to run the visualization through a whole dataset (about 500 images), my computer crashed at the 5th image(I suspect maybe there are some variables I didn't release after each for loop, I spent time on this approach, didn't work well). 但是,当我尝试在python脚本中使用for循环以遍历整个数据集(约500张图像)进行可视化处理时,我的计算机在第5张图像时崩溃了(我怀疑可能有些变量在每次加载后都没有释放)循环,我花了一些时间在这种方法上,效果不佳)。

Therefore I decide to discard the gracefulness of python code and figure if I could write a BAT file that runs my visualization script one image at a time and then go to another image till it loops through the whole dataset? 因此,我决定放弃python代码的优美性,想一想是否可以编写一个BAT文件,一次运行一个可视化脚本一个图像,然后转到另一个图像,直到遍历整个数据集?

Right now I have the bash command works for a single image: 现在,我有bash命令适用于单个图像:

@echo off
python main_single_img.py -i "./data/sample_folder_0/image0.jpg" --no-cuda %*
pause

I'm completely new to shell code, no idea how to run through all .jpg files in this "./data/sample_folder_0/" directory. 我对Shell代码是完全陌生的,不知道如何运行此“ ./data/sample_folder_0/”目录中的所有.jpg文件。 Need help! 需要帮忙!

Fortunately, I just solved this problem myself. 幸运的是,我自己解决了这个问题。 But thank you guys anyway. 但是还是谢谢你们。 Hope someone else with the same situation I encountered could see this post and save their time! 希望其他遇到我的情况相同的人可以看到这篇文章并节省时间!

@echo off
for %%f in (./data/sample_folder_0/*.jpg) do (
    echo %%~nf
    python main_single_img.py -i ./data/sample_folder_0/%%f --no-cuda %*
)
pause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM