服务器运行按顺序连续运行python脚步或训练程序(后一个用到前一个结果)

参考:

https://stackoverflow.com/questions/1186789/what-is-the-best-way-to-call-a-script-from-another-script

https://blog.csdn.net/ruanxingzi123/article/details/83024727

https://stackoverflow.com/questions/3781851/run-a-python-script-from-another-python-script-passing-in-arguments?noredirect=1&lq=1

https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another?noredirect=1&lq=1

https://stackoverflow.com/questions/40623234/run-one-python-script-from-another-python-script?noredirect=1&lq=1

 

使用subprocess库

 

test1.py

import cv2

import os
import sys
DATASET = sys.argv[1]
os.environ['CUDA_VISIBLE_DEVICES'] = sys.argv[2]

print(DATASET)
print(os.environ['CUDA_VISIBLE_DEVICES'])

img = cv2.imread("../data/mydata/img/001.png", -1)
H,W = img.shape[:2]
center = (int(W/2), int(H/2))
center_offset = (int(W/2)+100, int(H/2)+100)
cv2.rectangle(img, center, center_offset, (0,255,0), 4)
content = 'test1'
cv2.putText(img, content, center_offset,
            cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,255), 2)
cv2.imwrite("./result_test1.png", img)

test2.py

import cv2

import os
import sys
DATASET = sys.argv[1]
os.environ['CUDA_VISIBLE_DEVICES'] = sys.argv[2]

print(DATASET)
print(os.environ['CUDA_VISIBLE_DEVICES'])

img = cv2.imread("./result_test1.png", -1)
H,W = img.shape[:2]
center = (int(W/2), int(H/2))
center_offset = (int(W/2)+200, int(H/2)+200)
cv2.rectangle(img, center, center_offset, (0,255,0), 4)
content = 'test2'
cv2.putText(img, content, center_offset,
            cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,255), 2)

cv2.imwrite("./result_test2.png", img)

test3.py

import cv2

import os
import sys
DATASET = sys.argv[1]
os.environ['CUDA_VISIBLE_DEVICES'] = sys.argv[2]

print(DATASET)
print(os.environ['CUDA_VISIBLE_DEVICES'])

img = cv2.imread("./result_test2.png", -1)
H,W = img.shape[:2]
center = (int(W/2), int(H/2))
center_offset = (int(W/2)+300, int(H/2)+300)
cv2.rectangle(img, center, center_offset, (0,255,0), 4)
content = 'test3'
cv2.putText(img, content, center_offset,
            cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,255), 2)
cv2.imwrite("./result_test3.png", img)

test_process.py 

import subprocess

python_path = "/home/***/.conda/envs/py3_6--pytorch1_1_0/bin/python"


A = subprocess.run(python_path + " test1.py mydata 0", shell=True, check=True)
B = subprocess.run(python_path + " test2.py mydata 2", shell=True, check=True)
C = subprocess.run(python_path + " test3.py mydata 1", shell=True, check=True)

test_shell.sh

#!/usr/bin/env bash

#PYTHON=/root/train/***/anaconda3_py3.7/bin/python
PYTHON=/home/***/.conda/envs/py3_6--pytorch1_1_0/bin/python
nohup $PYTHON test_process.py > test_result.log 2>&1 &

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值