当前位置: 首页>>代码示例>>Python>>正文


Python os.mkdirs方法代码示例

本文整理汇总了Python中os.mkdirs方法的典型用法代码示例。如果您正苦于以下问题:Python os.mkdirs方法的具体用法?Python os.mkdirs怎么用?Python os.mkdirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.mkdirs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copy_readme_from_github

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def copy_readme_from_github(model_name, target_path):
    print("downloading %s from github..." % model_name)
    online_path = "https://github.com/thu-coai/%s/archive/master.zip" % model_name
    local_path = os.path.join("..", "build", model_name + ".zip")
    build_dir = os.path.join("..", "build")
    local_dir = os.path.join("..", "build", model_name + "-master")
    #os.mkdirs(local_path, exist_ok=True)
    if os.path.exists(local_path):
        print("skipping %s" % model_name)
    else:
        _http_get(online_path, open(local_path, "wb"))
    unzip_file(local_path, build_dir)
    shutil.copy(os.path.join(local_dir, "Readme.md"),
            os.path.join(target_path, "Readme.md"))
    shutil.copytree(os.path.join(local_dir, "images"),
            os.path.join(target_path, "images")) 
开发者ID:thu-coai,项目名称:cotk,代码行数:18,代码来源:conf.py

示例2: execute_frama_c

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def execute_frama_c(self, main):
        if not os.path.islink(self.shortdest):
        #    print self.shortdest
        #    print self.patchdest
            os.symlink(self.patchdest, self.shortdest)
        if len(self.backupdir) > 0:
            if not os.path.isdir(self.backupdir):
                os.mkdirs(self.backupdir)

            [shutil.copyfile(f.pp_path,
                             os.path.join(self.backupdir,
                                          os.path.basename(f.pp_path)))
             for f in self.preprocessed_files]

        cmd = "%s %s %s %s %s" % (self.frama_c, self.paths(),
                                  self.frama_c_main_arg, main, self.frama_c_args)
        if self.execute:
            if self.verbose:
                print cmd
            self.get_cmd_results(cmd)
        else:
            print cmd
            print "\n" 
开发者ID:bx,项目名称:bootloader_instrumentation_suite,代码行数:25,代码来源:frama_c.py

示例3: vis_whtml

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def vis_whtml(im_path, im, captions, dets, pre_results=dict(),
              thresh=0.5, save_path='./vis/data'):
    print("visualizing with pretty html...")
    if not os.path.exists(save_path):
        os.mkdirs(save_path)

    im_name = im_path.split('/')[-1][:-4]
    box_xywh = []
    box_caps = []
    scores = []
    for i in xrange(dets.shape[0]):
        if dets[i, -1] > thresh:
            box_xywh.append(box2xywh(dets[i, :4].tolist()))
            box_caps.append(captions[i])
            scores.append(float(dets[i, -1]))

    # save image
    im_new = np.copy(im)
    cv2.imwrite("%s/%s.jpg" % (save_path, im_name), im_new)
    result = {"img_name": "%s.jpg" % im_name,
              "scores": scores,
              "captions": box_caps,
              "boxes": box_xywh}
    pre_results["results"] = pre_results.get("results", []) + [result]

    return pre_results 
开发者ID:InnerPeace-Wu,项目名称:densecap-tensorflow,代码行数:28,代码来源:vis_whtml.py

示例4: _cache_fname

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def _cache_fname(self, cache_dir):
        # TODO: Potential problem if multiple SpikeTrains are opened at the same time, add salt to prevent collisions
        if not os.path.exists(self._cache_dir):
            os.mkdirs(self._cache_dir)
        return os.path.join(cache_dir, '.sonata.spikes.cache.csv') 
开发者ID:AllenInstitute,项目名称:sonata,代码行数:7,代码来源:spike_train_buffer.py

示例5: save

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def save(self):
        """ Save the file on the local file system. Simply builds the paths
        and calls :meth:`werkzeug.datastructures.FileStorage.save` on the
        file object.
        """

        fp = self.fp
        filename = self.safe_filename(self.filename)
        path = self.join(self.store_path, filename)
        directory = os.path.dirname(path)

        if not os.path.exists(directory):
            # Taken from Django - Race condition between os.path.exists and
            # os.mkdirs
            try:
                os.makedirs(directory)
            except OSError as e:
                if e.errno != errno.EEXIST:
                    raise

        if not os.path.isdir(directory):
            raise IOError('{0} is not a directory'.format(directory))

        # Save the file
        fp.save(path)
        fp.close()

        # Update the filename - it may have changes
        self.filename = filename 
开发者ID:thisissoon,项目名称:Flask-Store,代码行数:31,代码来源:local.py

示例6: makedirs

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def makedirs(self, path):
        """
        Creates all missing directories specified by name. Analogue to os.mkdirs().
        """
        return self.client.mkdir(path) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:7,代码来源:filebrowser_webdav_file_storage.py

示例7: create_stl10

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def create_stl10(source = 'unlabeled_X.bin', outdir = 'slt10'):
    '''
    Generate SLT-10 images from matlab files.
    '''
    with open(source, 'rb') as f:
        # read whole file in uint8 chunks
        everything = np.fromfile(f, dtype=np.uint8)

        # We force the data into 3x96x96 chunks, since the
        # images are stored in "column-major order", meaning
        # that "the first 96*96 values are the red channel,
        # the next 96*96 are green, and the last are blue."
        # The -1 is since the size of the pictures depends
        # on the input file, and this way numpy determines
        # the size on its own.

        images = np.reshape(everything, (-1, 3, 96, 96))

        # Now transpose the images into a standard image format
        # readable by, for example, matplotlib.imshow
        # You might want to comment this line or reverse the shuffle
        # if you will use a learning algorithm like CNN, since they like
        # their channels separated.
        images = np.transpose(images, (0, 3, 2, 1))
        images = images.astype(float) / 255.0
        
        if not os.path.exists(outdir):
            os.mkdirs(outdir)

        nb_imgs = np.shape(images)[0]
        for ii in range(nb_imgs):
            print(ii, nb_imgs)
            img = resize(images[ii,:,:,:], [48, 48])
            imwrite(img, os.path.join(outdir, 'image_%06d.png' %(ii))) 
开发者ID:tntrung,项目名称:gan,代码行数:36,代码来源:create_stl10.py

示例8: train

# 需要导入模块: import os [as 别名]
# 或者: from os import mkdirs [as 别名]
def train(model, optimizer, dataloader_src, dataloader_tar):
    loss_class = torch.nn.CrossEntropyLoss()
    best_acc = -float('inf')
    len_dataloader = min(len(dataloader_src), len(dataloader_tar))
    for epoch in range(args.nepoch):
        model.train()
        i = 1
        for (data_src, data_tar) in tqdm.tqdm(zip(enumerate(dataloader_src), enumerate(dataloader_tar)), total=len_dataloader, leave=False):
            _, (x_src, y_src) = data_src
            _, (x_tar, _) = data_tar
            x_src, y_src, x_tar = x_src.to(
                DEVICE), y_src.to(DEVICE), x_tar.to(DEVICE)
            p = float(i + epoch * len_dataloader) / args.nepoch / len_dataloader
            alpha = 2. / (1. + np.exp(-10 * p)) - 1

            class_output, err_s_domain = model(input_data=x_src, alpha=alpha)
            err_s_label = loss_class(class_output, y_src)
            _, err_t_domain = model(
                input_data=x_tar, alpha=alpha, source=False)
            err_domain = err_t_domain + err_s_domain
            err = err_s_label + args.gamma * err_domain
            optimizer.zero_grad()
            err.backward()
            optimizer.step()
            i += 1
        item_pr = 'Epoch: [{}/{}], classify_loss: {:.4f}, domain_loss_s: {:.4f}, domain_loss_t: {:.4f}, domain_loss: {:.4f},total_loss: {:.4f}'.format(
            epoch, args.nepoch, err_s_label.item(), err_s_domain.item(), err_t_domain.item(), err_domain.item(), err.item())
        print(item_pr)
        fp = open(args.result_path, 'a')
        fp.write(item_pr + '\n')

        # test
        acc_src = test(model, args.source, epoch)
        acc_tar = test(model, args.target, epoch)
        test_info = 'Source acc: {:.4f}, target acc: {:.4f}'.format(acc_src, acc_tar)
        fp.write(test_info + '\n')
        print(test_info)
        fp.close()
        
        if best_acc < acc_tar:
            best_acc = acc_tar
            if not os.path.exists(args.model_path):
                os.mkdirs(args.model_path)
            torch.save(model, '{}/mnist_mnistm.pth'.format(args.model_path))
    print('Test acc: {:.4f}'.format(best_acc)) 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:47,代码来源:main.py


注:本文中的os.mkdirs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。