This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Runs a toy image generation task on Dask. | |
# | |
# Note that the code was shortened for better readability. | |
# Please refer the following repository to see the full example: | |
# https://github.com/devforfu/dask_benchmark | |
@cli | |
def main(task_params: TaskParams) -> None: | |
jobs = [ | |
Job( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/ck/.conda/envs/codex/bin/python | |
""" | |
The script wrapping OpenAI client into a simple CLI. Was generated using Codex with minor manual tweaks. | |
""" | |
import sys | |
from argparse import ArgumentParser | |
from dataclasses import dataclass | |
from typing import Dict, List | |
import openai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
params = create_default_parser(__file__).parse_args() | |
super_seed(params.seed) | |
loaders, meta = create_data_loaders(dataset_name=params.dataset, | |
dataset_root=params.dataset_path, | |
num_workers=params.num_workers, | |
batch_size=params.batch_size, | |
sample_transformer=transforms.Compose([ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BasicCNNExperiment(BaseExperiment): | |
def create_model(self) -> nn.Module: | |
return nn.Sequential( | |
nn.Conv2d(3, 16, 3), | |
nn.ReLU(inplace=True), | |
nn.Conv2d(16, 32, 3), | |
nn.ReLU(inplace=True), | |
nn.AdaptiveMaxPool2d(1), | |
nn.Flatten(1, -1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def basic_parser(script_filename: str = None) -> ArgumentParser: | |
experiment_name = ( | |
Path(script_filename).stem | |
if script_filename is not None | |
else None | |
) | |
datasets = available_datasets() | |
p = ArgumentParser() | |
p.add_argument('--dataset_path', required=True) | |
p.add_argument('--dataset', choices=datasets, default=datasets[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_data_loaders( | |
dataset_root: str, | |
dataset_name: str, | |
sample_transformer: Callable = None, | |
target_transformer: Callable = None, | |
num_workers: int = cpu_count(), | |
batch_size: int = 32, | |
download: bool = True, | |
pin_memory: bool = False, | |
) -> Tuple[OrderedDict, Dict]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class MathErrors: | |
ZeroDivision = 'division failed: argument {argument} is zero.' | |
NaN = 'multiplication failed: argument {argument} is not a number.' | |
OutOfRange = 'value {argument} should be in range [{a}, {b}), but {value} received' | |
def divide(a: float, b: float) -> float: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import traceback | |
from typing import Callable | |
def report_failure_traceback(logger: logging.Logger, exc: Exception) -> None: | |
logger.critical('*** Unexpected error ***') | |
logger.critical('') | |
lines = traceback.format_tb(exc.__traceback__) | |
lines = ''.join(lines).split('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(0008, 0018) SOP Instance UID UI: ID_3d2ea4e22 | |
(0008, 0060) Modality CS: 'CT' | |
(0010, 0020) Patient ID LO: 'ID_e758d530' | |
(0020, 000d) Study Instance UID UI: ID_ebb91b8154 | |
(0020, 000e) Series Instance UID UI: ID_57e1457f93 | |
(0020, 0010) Study ID SH: '' | |
(0020, 0032) Image Position (Patient) DS: ['-125', '26', '272.300049'] | |
(0020, 0037) Image Orientation (Patient) DS: ['1', '0', '0', '0', '1', '0'] | |
(0028, 0002) Samples per Pixel US: 1 | |
(0028, 0004) Photometric Interpretation CS: 'MONOCHROME2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
from pdb import set_trace | |
from multiprocessing import cpu_count | |
from pprint import pprint as pp | |
from imageio import imread | |
import numpy as np | |
import pandas as pd | |
import PIL.Image |
NewerOlder