Colab command line

Since the free version of Colab cannot directly use the terminal, it can only be realized through command line statements in the notebook


The actual measurement found that the initial path of the Colab terminal is\content equivalent to that of the Windows terminal:C:\content>

insert image description here
Therefore, when running region_control.py through the command line in the notebook, it should be executed !python /content/multidiffusion-region-based/region_control.py( it cannot be written !python /multidiffusion-region-based/region_control.py, it must be /contentadded) , which is equivalent to the Windows terminal like this:C:\content>python multidiffusion-region-based\region_control.py

The path of the mask map was originally masks/XXX.png, indicating the relative path between mask.png and region_control.py, it should be changed now /content/multidiffusion-region-based/masks/XXX.png( it cannot be written /multidiffusion-region-based/masks/XXX.png, it must be /contentadded ), because the current root path is /content, if it is still masks/XXX.png, an error will be reported can't find/content/masks/XXX.png

At the same time, it can also be found that the output result out.pngshould have been in the same directory as region_control.py, but it is also \content\out.pngin it now, not \content\multidiffusion-region-based\out.pngin


If you want to use the relative path between mask.png and region_control.py as you usually run region_control.py, you should do this in the Windows terminal:

# 先切换路径到multidiffusion-region-based下
C:\content>cd multidiffusion-region-based
C:\content\multidiffusion-region-based>python region_control.py

The corresponding code is (I don’t know why it’s invalid to use !cd, but it’s OK to use %cd):

# 先切换路径到/content/multidiffusion-region-based下,不能写成%cd /multidiffusion-region-based,必须把/content加上
%cd /content/multidiffusion-region-based 
!python region_control.py

Guess you like

Origin blog.csdn.net/m0_52848925/article/details/131364911