python脚本中调用其他脚本

如果只关注脚本中调用他脚本直接看代码30行

PS:该脚本功能有:自动清理目录,创建目录,自动运行脚本,以此提升工作效率

import numpy as np
import os
from shutil import copyfile, rmtree

class vae_auto():
    def __init__(self, name):
        self.ROOTPATH = './'
        self.DSTPATH = os.path.join(self.ROOTPATH, name)
        self.FAKECOPY = os.path.join(self.ROOTPATH, 'fake_' + name)
        self.MODELSCOPY = os.path.join(self.ROOTPATH, 'models_' + name)
        self.MODELS = os.path.join(self.ROOTPATH, 'models')
        self.DATAORG = os.path.join(self.ROOTPATH, 'data_org')
        self.DATASETS = os.path.join(self.ROOTPATH, 'datasets')
        self.DATARESIZE = os.path.join(self.ROOTPATH, 'data_resize')
        self.IMGS = os.path.join(self.ROOTPATH, 'imgs')
        self.FAKE = os.path.join(self.ROOTPATH, 'fake')
    
    def clean_folds(self):
        dirs = [self.DATAORG, self.DATASETS, self.DATARESIZE, self.IMGS, self.FAKE, self.FAKECOPY, self.MODELSCOPY]
        for n in dirs:
            if os.path.exists(n):
                rmtree(n)
            os.makedirs(n)
        list_name = os.listdir(self.DSTPATH)
        for m in list_name:
            print(m)
            copyfile(self.DSTPATH + '/' + m, self.DATAORG + '/' + m)
    
    def datasets(self):
        activate_this = 'lala.py' # 方便调试,用简单的脚本验收功能
        execfile(activate_this, dict(__file__=activate_this))
    
    def train(self):
        activate_this = 'lala.py'
        execfile(activate_this, dict(__file__=activate_this))
    
    def save_data(self):
        activate_this = 'lala.py'
        execfile(activate_this, dict(__file__=activate_this))
        list_name = os.listdir(self.FAKE)
        for n in list_name:
            copyfile(self.FAKE+'/'+n, self.FAKECOPY+'/'+n)
        list_name_2 = os.listdir(self.MODELS)
        for m in list_name_2:
            copyfile(self.MODELS+'/'+m, self.MODELSCOPY+'/'+m)

if __name__ == "__main__":
    vae = vae_auto('abc') #原始数据目录
    vae.clean_folds()
    vae.datasets()
    vae.train()
    vae.save_data()

  

posted @ 2019-09-19 16:27  牛郎  阅读(2105)  评论(0编辑  收藏  举报