本文整理汇总了Python中pathlib.Path.mkdir方法的典型用法代码示例。如果您正苦于以下问题:Python Path.mkdir方法的具体用法?Python Path.mkdir怎么用?Python Path.mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pathlib.Path
的用法示例。
在下文中一共展示了Path.mkdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def __init__(self, env, rank=None):
self.rank = rank
if self.rank is not None:
log_path = Path(env, f"rank{rank}").resolve()
else:
log_path = Path(env).resolve()
logger.debug(f"using tensorboard on --logdir {str(log_path)}")
try:
Path.mkdir(log_path, parents=True, exist_ok=True)
except OSError as e:
if e.errno == errno.EEXIST:
logger.warning(f'Tensorboard log directory already exists: {str(log_path)}')
for f in log_path.rglob("*"):
f.unlink()
else:
raise
from tensorboardX import SummaryWriter
self.writer = SummaryWriter(str(log_path))
示例2: plot_tsne
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def plot_tsne(ssvae, test_loader, use_cuda=False):
xs = test_loader.dataset.test_data.float()
ys = test_loader.dataset.test_labels
z_mu, z_sigma = ssvae.guide_sample(xs, ys, len(test_loader))
z_states = z_mu.data.cpu().numpy()
classes = ys.cpu().numpy()
logger.info("calculating T-SNE of z embedding..")
if use_cuda:
import t_sne_bhcuda.bhtsne_cuda as tsne_bhcuda
files_dir = Path.cwd() / "tsne"
Path.mkdir(files_dir, parents=True, exist_ok=True)
z_embed = tsne_bhcuda.t_sne(z_states, no_dims=2, files_dir=files_dir, gpu_mem=0.9)
z_embed = np.array([list(x) for x in z_embed])
else:
from sklearn.manifold import TSNE
model_tsne = TSNE(n_components=2, random_state=0)
z_embed = model_tsne.fit_transform(z_states)
__plot_tsne_to_visdom(z_embed, classes)
#__plot_tsne_to_matplotlib(z_embed, classes)
示例3: get_elmo_model
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def get_elmo_model( model_dir, cpu, verbose ):
weights_path = model_dir / 'weights.hdf5'
options_path = model_dir / 'options.json'
# if no pre-trained model is available, yet --> download it
if not (weights_path.exists() and options_path.exists()):
if verbose:
print('No existing model found. Start downloading pre-trained SeqVec (~360MB)...')
import urllib.request
Path.mkdir(model_dir)
repo_link = 'http://rostlab.org/~deepppi/embedding_repo/embedding_models/seqvec'
options_link = repo_link +'/options.json'
weights_link = repo_link +'/weights.hdf5'
urllib.request.urlretrieve( options_link, options_path )
urllib.request.urlretrieve( weights_link, weights_path )
cuda_device = 0 if torch.cuda.is_available() and not cpu else -1
return ElmoEmbedder( weight_file=weights_path, options_file=options_path, cuda_device=cuda_device )
示例4: test_fsdir_missing_space
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def test_fsdir_missing_space(tmp_path):
fshome = os.environ["FREESURFER_HOME"]
# fsaverage2 doesn't exist in source or destination, so can't copy
with pytest.raises(FileNotFoundError):
bintfs.BIDSFreeSurferDir(
derivatives=str(tmp_path), spaces=["fsaverage2"], freesurfer_home=fshome
).run()
subjects_dir = tmp_path / "freesurfer"
# If fsaverage2 exists in the destination directory, no error is thrown
Path.mkdir(subjects_dir / "fsaverage2")
bintfs.BIDSFreeSurferDir(
derivatives=str(tmp_path), spaces=["fsaverage2"], freesurfer_home=fshome
).run()
示例5: create_browser_output
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def create_browser_output(fig, outfile, window):
if outfile is None:
outfile = "methylation_browser_{}.html".format(window.string)
else:
from pathlib import Path
outfile = outfile.format(region=window.string)
p = Path(outfile)
Path.mkdir(p.parent, exist_ok=True, parents=True)
if outfile.endswith(".html"):
write_html_output(fig, outfile)
else:
try:
fig.write_image(outfile)
except ValueError as e:
sys.stderr.write("\n\nERROR: creating the image in this file format failed.\n")
sys.stderr.write("ERROR: creating in default html format instead.\n")
sys.stderr.write("ERROR: additional packages required. Detailed error:\n")
sys.stderr.write(str(e))
write_html_output(fig, outfile)
示例6: create_cache_dirs
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def create_cache_dirs(cache_file: Path) -> None:
"""Create the ``__pycache__`` directories if needed for the ``cache_file``.
Args:
cache_file: Path to the cache_file
Returns:
None, creates the cache directory on disk if needed.
"""
if not cache_file.parent.exists():
# exists_ok shouldn't be needed with exists() check, suppressing FileExistsErrors
Path.mkdir(cache_file.parent, parents=True, exist_ok=True)
示例7: create_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def create_dir(name):
if not Path.exists(name):
Path.mkdir(name)
示例8: create_directory
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def create_directory(course_directory):
course_dir = Path(course_directory)
try:
Path.mkdir(course_dir, mode=0o777)
except FileExistsError as err:
pass
return course_dir
示例9: run_lithium
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def run_lithium(lithArgs, logPrefix, targetTime): # pylint: disable=invalid-name,missing-param-doc,missing-return-doc
# pylint: disable=missing-return-type-doc,missing-type-doc
"""Run Lithium as a subprocess: reduce to the smallest file that has at least the same unhappiness level.
Returns a tuple of (lithlogfn, LITH_*, details).
"""
deletableLithTemp = None # pylint: disable=invalid-name
if targetTime:
# loop is being used by bot
deletableLithTemp = tempfile.mkdtemp(prefix="fuzzbot-lithium") # pylint: disable=invalid-name
lithArgs = [f"--maxruntime={targetTime}", f"--tempdir={deletableLithTemp}"] + lithArgs
else:
# loop is being run standalone
lithtmp = logPrefix.parent / f"{logPrefix.stem}-lith-tmp"
Path.mkdir(lithtmp)
lithArgs = [f"--tempdir={lithtmp}"] + lithArgs
lithlogfn = (logPrefix.parent / f"{logPrefix.stem}-lith-out").with_suffix(".txt")
print(f"Preparing to run Lithium, log file {lithlogfn}")
print(" ".join(quote(str(x)) for x in runlithiumpy + lithArgs))
with io.open(str(lithlogfn), "w", encoding="utf-8", errors="replace") as f:
subprocess.run(runlithiumpy + lithArgs, check=False, stderr=subprocess.STDOUT, stdout=f)
print("Done running Lithium")
if deletableLithTemp:
shutil.rmtree(deletableLithTemp)
r = readLithiumResult(lithlogfn) # pylint: disable=invalid-name
with open(lithlogfn, "rb") as f_in: # Replace the old gzip subprocess call
with gzip.open(lithlogfn.with_suffix(".txt.gz"), "wb") as f_out:
shutil.copyfileobj(f_in, f_out)
lithlogfn.unlink()
return r
示例10: make_dirs
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def make_dirs(dir_pathes: Union[str, List[str]]) -> None:
"""Create one or more directories."""
if isinstance(dir_pathes, str):
dir = Path(dir_pathes)
Path.mkdir(dir, parents=True, exist_ok=True)
elif isinstance(dir_pathes, list):
for dir_path in dir_pathes:
dir = Path(dir_path)
Path.mkdir(dir, parents=True, exist_ok=True)
示例11: crawl
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def crawl(site, crawl_page_limit=500, restart=True):
print('Crawling up to %s pages from %s' % (crawl_page_limit, site))
pickles = Path.cwd() / 'crawl'
if not pickles.exists():
Path.mkdir(pickles)
unvisited_filename = pickles / 'unvisited.pkl'
visited_filename = pickles / 'visited.pkl'
alllinks_filename = pickles / 'alllinks.pkl'
if restart:
page_links = links(site)
persist(set(page_links), unvisited_filename)
persist(set(), visited_filename)
persist(set(), alllinks_filename)
msg = ''
for i, alink in enumerate(persists(unvisited_filename)):
unvisited = persists(unvisited_filename)
unvisited.remove(alink)
visited = persists(visited_filename)
if crawl_page_limit != False and len(visited) > crawl_page_limit:
print('Hit crawl page limit.')
break
visited.add(alink)
new_links = links(alink.url)
all_links = persists(alllinks_filename)
all_links = all_links | set(new_links)
persist(all_links, alllinks_filename)
msg = "%s. Unvisited: %s, Visited: %s" % (i + 1, len(unvisited), len(visited))
print(msg)
for new_link in new_links:
if new_link not in visited:
visited.add(new_link)
persist(visited, visited_filename)
persist(unvisited, unvisited_filename)
print('Done crawl')
return all_links
示例12: visualize_setup
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def visualize_setup(image_dir):
assert viz.check_connection(), "visdom server is not working!"
try:
global result_dir
Path.mkdir(Path(image_dir), parents=True, exist_ok=True)
result_dir = image_dir
except:
raise()
示例13: mkdir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def mkdir(directory: Path) -> None:
"""
Not Path.mkdir() for compatibility with Python 3.4.
"""
makedirs(str(directory), exist_ok=True)
示例14: __init__
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def __init__(self, *, max_processes=20, loop=None, cache_dir=DFT_CACHE_DIR):
self.semaphore = asyncio.Semaphore(value=max_processes, loop=loop)
self.loop = loop
if not cache_dir.exists():
Path.mkdir(cache_dir)
self.cache_dir = cache_dir
示例15: load
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import mkdir [as 别名]
def load():
path = Path('.')
global model
global learn
global classes
model = CONFIG['model_name']
# Check if we need to download Model file
if CONFIG[model]['url'] != "":
try:
logging.info(f"Downloading model file from: {CONFIG[model]['url']}")
urllib.request.urlretrieve(CONFIG[model]['url'], f"models/{model}.pth")
logging.info(f"Downloaded model file and stored at path: models/{model}.pth")
except HTTPError as e:
logging.critical(f"Failed in downloading file from: {CONFIG[model]['url']}, Exception: '{e}'")
sys.exit(4)
init_data = ImageDataBunch.single_from_classes(
path, CONFIG[model]['classes'], tfms=get_transforms(),
size=CONFIG[model]['size']
).normalize(imagenet_stats)
classes = CONFIG[model]['classes']
logging.info(f"Loading model: {CONFIG['model_name']}, architecture: {CONFIG[model]['arch']}, file: models/{model}.pth")
learn = create_cnn(init_data, eval(f"models.{CONFIG[model]['arch']}"))
learn.load(model, device=CONFIG[model]['device'])
# Create direcotry to get feedback for this model
Path.mkdir(Path(path_to(FEEDBACK_DIR, model)), parents=True, exist_ok=True)