當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。