id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
31,724
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def console_print(text, width=75): last_newline = 0 i = 0 while i < len(text): if text[i] == "\n": last_newline = 0 elif last_newline > width and text[i] == " ": tex...
null
31,725
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def get_similarity(a, b): return SequenceMatcher(None, a, b).ratio()
null
31,726
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def get_num_options(num): while True: choice = input("Enter the number of your choice: ") try: result = int(choice) if result >= 0 and result < num: return ...
null
31,727
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter The provided code snippet includes necessary dependencies for implementing the `player_died` function. Write a Python function `def player_died(text)` to solve the following problem: TODO: Add in more sophisticated NL...
TODO: Add in more sophisticated NLP, maybe a custom classifier trained on hand-labelled data that classifies second-person statements as resulting in death or not.
31,728
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def player_won(text): lower_text = text.lower() won_phrases = [ "you ((\w* )*and |)live happily ever after", "you ((\w* )*and |)live (forever|eternally|for eternity)", "you ((\w* )*and ...
null
31,729
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter pf = ProfanityFilter(custom_censor_list=censored_words) def remove_profanity(text): return pf.censor(text)
null
31,730
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def split_first_sentence(text): first_period = text.find(".") first_exclamation = text.find("!") if first_exclamation < first_period and first_exclamation > 0: split_point = first_exclamation + 1 ...
null
31,731
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def cut_trailing_quotes(text): num_quotes = text.count('"') if num_quotes % 2 is 0: return text else: final_ind = text.rfind('"') return text[:final_ind] def cut_trailing_action(text...
null
31,732
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def mapping_variation_pairs(mapping): mapping_list = [] mapping_list.append((" " + mapping[0] + " ", " " + mapping[1] + " ")) mapping_list.append( (" " + capitalize(mapping[0]) + " ", " " + capitali...
null
31,733
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def mapping_variation_pairs(mapping): second_to_first_mappings = [ ("you're", "I'm"), ("your", "my"), ("you are", "I am"), ("you were", "I was"), ("are you", "am I"), ("you", "I"), ("you", "...
null
31,734
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def replace_outside_quotes(text, current_word, repl_word): def mapping_variation_pairs(mapping): first_to_second_mappings = [ ("I'm", "you're"), ("Im", "you're"), ("Ive", "you've"), ("I am", "you are"),...
null
31,735
import re from difflib import SequenceMatcher import yaml from profanityfilter import ProfanityFilter def replace_outside_quotes(text, current_word, repl_word): text = standardize_punctuation(text) reg_expr = re.compile(current_word + '(?=([^"]*"[^"]*")*[^"]*$)') output = reg_expr.sub(repl_word, text) r...
null
31,736
import json import os from story.utils import * with open(output_file_path, "w") as output_file: filenames = ["writingprompts/" + file for file in files] cleaned_stories = [] for filename in filenames: print("Processing file ", filename) stories = load_stories(filename) for story in ...
null
31,737
import json import os from story.utils import * def modify_story(story): text = story["body"] if len(text) < 100: return None first_person = is_first_person(text) second_person = is_second_person(text) if first_person or second_person: return first_to_second_person(text) else:...
null
31,738
import json import time from selenium import webdriver from selenium.webdriver.chrome.options import Options def save_tree(tree, filename): with open(filename, "w") as fp: json.dump(tree, fp)
null
31,739
import csv import json from story.utils import * def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def make_stories(current_story, tree): stories = [] action = first_to_second_person(tree["action"]) action_list = action.split(" ") first_word = acti...
null
31,740
import csv import json import os def data_to_forest(filename): trees = [] rows = [] with open(filename, newline="") as f: reader = csv.reader(f) for row in reader: rows.append(row) for i in range(1, len(rows[0])): tree = {} tree["tree_id"] = rows[0][i] ...
null
31,741
import csv import json import os def build_action_samples_helper(context, story_block, action_results, path, tree_id): samples = [] for i, action_result in enumerate(action_results): new_path = path[:] new_path.append(i) if ( len(action_result["action_results"]) is 0 ...
null
31,742
import csv import json import os def build_result_samples_helper( context, story_block, parent_action_result, path, tree_id ): samples = [] action_results = parent_action_result["action_results"] for i, action_result in enumerate(action_results): new_path = path[:] new_path.append(i) ...
null
31,743
import csv import json import os def save_tree(tree, filename): def save_forest(forest, forest_name): if not os.path.exists("./" + forest_name): os.mkdir("./" + forest_name) for tree in forest: save_tree(tree, "./" + forest_name + "/" + tree["tree_id"] + ".json")
null
31,744
import csv import json import os def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def load_forest(forest_name): files = os.listdir("./" + forest_name) forest = [] for file in files: forest.append(load_tree("./" + forest_name + "/" + file)) ...
null
31,745
import csv import json import os def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def csv_to_dict(file): update_dict = {} field_names = [] with open(file, newline="") as f: reader = csv.reader(f) for row in reader: if len(u...
null
31,746
import csv import json import os def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def csv_to_dict(file): update_dict = {} field_names = [] with open(file, newline="") as f: reader = csv.reader(f) for row in reader: if len(u...
null
31,747
import csv import json import os tree = data_to_forest("upwork.csv") for i, story in enumerate(tree): save_tree(story, "crowdsourcedstory" + str(i) + ".json") def data_to_forest(filename): trees = [] rows = [] with open(filename, newline="") as f: reader = csv.reader(f) for row in rea...
null
31,748
import csv import json import os def build_action_samples_helper(context, story_block, action_results, path, tree_id): samples = [] for i, action_result in enumerate(action_results): new_path = path[:] new_path.append(i) if ( len(action_result["action_results"]) is 0 ...
null
31,749
import csv import json import os def build_result_samples_helper( context, story_block, parent_action_result, path, tree_id ): tree = data_to_forest("upwork.csv") for i, story in enumerate(tree): save_tree(story, "crowdsourcedstory" + str(i) + ".json") def make_write_results_batch(forest, filename): with ...
null
31,750
import csv import json import os def save_tree(tree, filename): with open(filename, "w") as fp: json.dump(tree, fp) tree = data_to_forest("upwork.csv") def save_forest(forest, forest_name): if not os.path.exists("./" + forest_name): os.mkdir("./" + forest_name) for tree in forest: ...
null
31,752
import csv import json import os def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def csv_to_dict(file): update_dict = {} field_names = [] with open(file, newline="") as f: reader = csv.reader(f) for row in reader: if len(u...
null
31,753
import csv import json import os def load_tree(filename): with open(filename, "r") as fp: tree = json.load(fp) return tree def csv_to_dict(file): update_dict = {} field_names = [] with open(file, newline="") as f: reader = csv.reader(f) for row in reader: if len(u...
null
31,754
import os import random import sys import time import argparse from generator.gpt2.gpt2_generator import * from story import grammars from story.story_manager import * from story.utils import * def splash(): print("0) New Game\n1) Load Game\n") choice = get_num_options(2) if choice == 1: return "loa...
Entry/main function for starting AIDungeon 2 Arguments: args (namespace): Arguments returned by the ArgumentParser
31,755
import tensorflow as tf from generator.gpt2.src import model def penalize_used(logits, output): # I want to change the indices of logits wherever the index is found in output change_tensor = tf.zeros_like(logits, dtype=logits.dtype) unique = tf.unique(output[0])[0] ones = tf.ones_like(unique, dtype=uniq...
null
31,756
import numpy as np import tensorflow as tf from tensorflow.contrib.training import HParams def default_hparams(): return HParams(n_vocab=0, n_ctx=1024, n_embd=768, n_head=12, n_layer=12,)
null
31,757
import json import os from functools import lru_cache import regex as re The provided code snippet includes necessary dependencies for implementing the `bytes_to_unicode` function. Write a Python function `def bytes_to_unicode()` to solve the following problem: Returns list of utf-8 byte and a corresponding list of un...
Returns list of utf-8 byte and a corresponding list of unicode strings. The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for decent coverage. This ...
31,758
import json import os from functools import lru_cache import regex as re The provided code snippet includes necessary dependencies for implementing the `get_pairs` function. Write a Python function `def get_pairs(word)` to solve the following problem: Return set of symbol pairs in a word. Word is represented as tuple ...
Return set of symbol pairs in a word. Word is represented as tuple of symbols (symbols being variable-length strings).
31,759
import json import os from functools import lru_cache import regex as re class Encoder: def __init__(self, encoder, bpe_merges, errors="replace"): self.encoder = encoder self.decoder = {v: k for k, v in self.encoder.items()} self.errors = errors # how to handle errors in decoding se...
null
31,760
import os import sys import time from generator.gpt2.gpt2_generator import * from generator.human_dm import * from play import * from story.story_manager import * from story.utils import * class AIPlayer: def __init__(self, generator): self.generator = generator def get_action(self, prompt): ret...
null
31,761
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import minigpt4.tasks as tasks from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank, init_distributed_mode from minigpt4.common.logger import setup_logger from minigpt4.commo...
null
31,762
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import minigpt4.tasks as tasks from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank, init_distributed_mode from minigpt4.common.logger import setup_logger from minigpt4.commo...
null
31,763
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import minigpt4.tasks as tasks from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank, init_distributed_mode from minigpt4.common.logger import setup_logger from minigpt4.commo...
Get runner class from config. Default to epoch-based runner.
31,764
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,765
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,766
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,767
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,768
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,769
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation_video import Ch...
null
31,770
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,771
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,772
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,773
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,774
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,775
import argparse import os import random import numpy as np import torch import torch.backends.cudnn as cudnn import gradio as gr from minigpt4.common.config import Config from minigpt4.common.dist_utils import get_rank from minigpt4.common.registry import registry from minigpt4.conversation.conversation import Chat, CO...
null
31,776
import cv2 import numpy as np import torch def identity_func(img): return img
null
31,777
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `autocontrast_func` function. Write a Python function `def autocontrast_func(img, cutoff=0)` to solve the following problem: same output as PIL.ImageOps.autocontrast Here is the function: def aut...
same output as PIL.ImageOps.autocontrast
31,778
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `equalize_func` function. Write a Python function `def equalize_func(img)` to solve the following problem: same output as PIL.ImageOps.equalize PIL's implementation is different from cv2.equalize ...
same output as PIL.ImageOps.equalize PIL's implementation is different from cv2.equalize
31,779
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `rotate_func` function. Write a Python function `def rotate_func(img, degree, fill=(0, 0, 0))` to solve the following problem: like PIL, rotate by degree, not radians Here is the function: def ro...
like PIL, rotate by degree, not radians
31,780
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `solarize_func` function. Write a Python function `def solarize_func(img, thresh=128)` to solve the following problem: same output as PIL.ImageOps.posterize Here is the function: def solarize_fun...
same output as PIL.ImageOps.posterize
31,781
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `color_func` function. Write a Python function `def color_func(img, factor)` to solve the following problem: same output as PIL.ImageEnhance.Color Here is the function: def color_func(img, factor...
same output as PIL.ImageEnhance.Color
31,782
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `contrast_func` function. Write a Python function `def contrast_func(img, factor)` to solve the following problem: same output as PIL.ImageEnhance.Contrast Here is the function: def contrast_func...
same output as PIL.ImageEnhance.Contrast
31,783
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `brightness_func` function. Write a Python function `def brightness_func(img, factor)` to solve the following problem: same output as PIL.ImageEnhance.Contrast Here is the function: def brightnes...
same output as PIL.ImageEnhance.Contrast
31,784
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `sharpness_func` function. Write a Python function `def sharpness_func(img, factor)` to solve the following problem: The differences the this result and PIL are all on the 4 boundaries, the center ...
The differences the this result and PIL are all on the 4 boundaries, the center areas are same
31,785
import cv2 import numpy as np import torch def shear_x_func(img, factor, fill=(0, 0, 0)): H, W = img.shape[0], img.shape[1] M = np.float32([[1, factor, 0], [0, 1, 0]]) out = cv2.warpAffine( img, M, (W, H), borderValue=fill, flags=cv2.INTER_LINEAR ).astype(np.uint8) return out
null
31,786
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `translate_x_func` function. Write a Python function `def translate_x_func(img, offset, fill=(0, 0, 0))` to solve the following problem: same output as PIL.Image.transform Here is the function: d...
same output as PIL.Image.transform
31,787
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `translate_y_func` function. Write a Python function `def translate_y_func(img, offset, fill=(0, 0, 0))` to solve the following problem: same output as PIL.Image.transform Here is the function: d...
same output as PIL.Image.transform
31,788
import cv2 import numpy as np import torch The provided code snippet includes necessary dependencies for implementing the `posterize_func` function. Write a Python function `def posterize_func(img, bits)` to solve the following problem: same output as PIL.ImageOps.posterize Here is the function: def posterize_func(i...
same output as PIL.ImageOps.posterize
31,789
import cv2 import numpy as np import torch def shear_y_func(img, factor, fill=(0, 0, 0)): H, W = img.shape[0], img.shape[1] M = np.float32([[1, 0, 0], [factor, 1, 0]]) out = cv2.warpAffine( img, M, (W, H), borderValue=fill, flags=cv2.INTER_LINEAR ).astype(np.uint8) return out
null
31,790
import cv2 import numpy as np import torch def cutout_func(img, pad_size, replace=(0, 0, 0)): replace = np.array(replace, dtype=np.uint8) H, W = img.shape[0], img.shape[1] rh, rw = np.random.random(2) pad_size = pad_size // 2 ch, cw = int(rh * H), int(rw * W) x1, x2 = max(ch - pad_size, 0), min...
null
31,791
import cv2 import numpy as np import torch def enhance_level_to_args(MAX_LEVEL): def level_to_args(level): return ((level / MAX_LEVEL) * 1.8 + 0.1,) return level_to_args
null
31,792
import cv2 import numpy as np import torch def shear_level_to_args(MAX_LEVEL, replace_value): def level_to_args(level): level = (level / MAX_LEVEL) * 0.3 if np.random.random() > 0.5: level = -level return (level, replace_value) return level_to_args
null
31,793
import cv2 import numpy as np import torch def translate_level_to_args(translate_const, MAX_LEVEL, replace_value): def level_to_args(level): level = (level / MAX_LEVEL) * float(translate_const) if np.random.random() > 0.5: level = -level return (level, replace_value) return...
null
31,794
import cv2 import numpy as np import torch def cutout_level_to_args(cutout_const, MAX_LEVEL, replace_value): def level_to_args(level): level = int((level / MAX_LEVEL) * cutout_const) return (level, replace_value) return level_to_args
null
31,795
import cv2 import numpy as np import torch def solarize_level_to_args(MAX_LEVEL): def level_to_args(level): level = int((level / MAX_LEVEL) * 256) return (level,) return level_to_args
null
31,796
import cv2 import numpy as np import torch def none_level_to_args(level): return ()
null
31,797
import cv2 import numpy as np import torch def posterize_level_to_args(MAX_LEVEL): def level_to_args(level): level = int((level / MAX_LEVEL) * 4) return (level,) return level_to_args
null
31,798
import cv2 import numpy as np import torch def rotate_level_to_args(MAX_LEVEL, replace_value): def level_to_args(level): level = (level / MAX_LEVEL) * 30 if np.random.random() < 0.5: level = -level return (level, replace_value) return level_to_args
null
31,799
import gzip import logging import os import random as rnd import tarfile import zipfile import random from typing import List from tqdm import tqdm import decord from decord import VideoReader import webdataset as wds import numpy as np import torch from torch.utils.data.dataset import IterableDataset from minigpt4.com...
null
31,800
import gzip import logging import os import random as rnd import tarfile import zipfile import random from typing import List from tqdm import tqdm import decord from decord import VideoReader import webdataset as wds import numpy as np import torch from torch.utils.data.dataset import IterableDataset from minigpt4.com...
Organizes datasets by split. Args: datasets: dict of torch.utils.data.Dataset objects by name. Returns: Dict of datasets by split {split_name: List[Datasets]}.
31,801
import gzip import logging import os import random as rnd import tarfile import zipfile import random from typing import List from tqdm import tqdm import decord from decord import VideoReader import webdataset as wds import numpy as np import torch from torch.utils.data.dataset import IterableDataset from minigpt4.com...
Concatenates multiple datasets into a single dataset. It supports may-style datasets and DataPipeline from WebDataset. Currently, does not support generic IterableDataset because it requires creating separate samplers. Now only supports conctenating training datasets and assuming validation and testing have only a sing...
31,802
import logging import os import shutil import warnings from omegaconf import OmegaConf import torch.distributed as dist from torchvision.datasets.utils import download_url import minigpt4.common.utils as utils from minigpt4.common.dist_utils import is_dist_avail_and_initialized, is_main_process from minigpt4.common.reg...
null
31,803
import time import random import torch from minigpt4.datasets.data_utils import move_to_cuda from torch.utils.data import DataLoader def record_cuda_stream(batch): if isinstance(batch, torch.Tensor): batch.record_stream(torch.cuda.current_stream()) elif isinstance(batch, list) or isinstance(batch, tupl...
null
31,804
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,805
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,806
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,807
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,808
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,809
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Utility function to transform a view URL of google drive to a download URL for google drive Example input: https://drive.google.com/file/d/137RyRjvTBkBiIfeYBNZBtViDHQ6_Ewsp/view Example output: https://drive.google.com/uc?export=download&id=137RyRjvTBkBiIfeYBNZBtViDHQ6_Ewsp
31,810
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Download a file from google drive Downloading an URL from google drive requires confirmation when the file of the size is too big (google drive notifies that anti-viral checks cannot be performed on such files)
31,811
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
null
31,812
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
This implementation downloads the remote resource and caches it locally. The resource will only be downloaded if not previously requested.
31,813
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Simply create the symlinks for a given file1 to file2. Useful during model checkpointing to symlinks to the latest successful checkpoint.
31,814
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Common i/o utility to handle saving data to various file formats. Supported: .pkl, .pickle, .npy, .json Specifically for .json, users have the option to either append (default) or rewrite by passing in Boolean value to append_to_json.
31,815
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Common i/o utility to handle loading data from various file formats. Supported: .pkl, .pickle, .npy, .json For the npy files, we support reading the files in mmap_mode. If the mmap_mode of reading is not successful, we load data without the mmap_mode.
31,816
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Make a path absolute, but take into account prefixes like "http://" or "manifold://"
31,817
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Check if an input string is a url. look for http(s):// and ignoring the case
31,818
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Utility for deleting a directory. Useful for cleaning the storage space that contains various training artifacts like checkpoints, data etc.
31,819
import io import json import logging import os import pickle import re import shutil import urllib import urllib.error import urllib.request from typing import Optional from urllib.parse import urlparse import numpy as np import pandas as pd import yaml from iopath.common.download import download from iopath.common.fil...
Given a file, get the size of file in MB
31,820
import numpy as np from matplotlib import pyplot as plt from scipy.ndimage import filters from skimage import transform as skimage_transform def getAttMap(img, attMap, blur=True, overlap=True): attMap -= attMap.min() if attMap.max() > 0: attMap /= attMap.max() attMap = skimage_transform.resize(attM...
null
31,821
import datetime import functools import os import torch import torch.distributed as dist import timm.models.hub as timm_hub def setup_for_distributed(is_master): def init_distributed_mode(args): if "RANK" in os.environ and "WORLD_SIZE" in os.environ: args.rank = int(os.environ["RANK"]) args.world_s...
null
31,822
import datetime import functools import os import torch import torch.distributed as dist import timm.models.hub as timm_hub def get_dist_info(): if torch.__version__ < "1.0": initialized = dist._initialized else: initialized = dist.is_initialized() if initialized: rank = dist.get_ran...
null
31,823
import datetime import functools import os import torch import torch.distributed as dist import timm.models.hub as timm_hub def is_dist_avail_and_initialized(): if not dist.is_available(): return False if not dist.is_initialized(): return False return True def is_main_process(): return g...
Download a file from a URL and cache it locally. If the file already exists, it is not downloaded again. If distributed, only the main process downloads the file, and the other processes wait for the file to be downloaded.
31,824
import logging import json from typing import Dict from omegaconf import OmegaConf from minigpt4.common.registry import registry def node_to_dict(node): return OmegaConf.to_container(node)
null