This file contains hidden or 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 argparse | |
def get_parser() -> argparse.ArgumentParser: | |
... | |
def process_args(args: argparse.Namespace) -> argparse.Namespace: | |
... |
This file contains hidden or 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 json | |
from enum import Enum | |
from typing import get_origin, get_args, Any, Dict, List | |
import streamlit as st | |
from pydantic import BaseModel | |
# Example Enum | |
class Color(str, Enum): |
This file contains hidden or 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 get_files_in_dir(rootdir: str , suffix: str, subdirs: bool = True) -> List[str]: | |
rootdir = Path(str(rootdir)) | |
if subdirs: | |
glob_pattern = "**/*" | |
else: | |
glob_pattern = "*" | |
files_lower = list(rootdir.glob(f"{glob_pattern}{suffix.lower()}")) | |
files_upper = list(rootdir.glob(f"{glob_pattern}{suffix.upper()}")) |
This file contains hidden or 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 | |
from copy import deepcopy | |
from typing import List, Dict, Any | |
from pathlib import Path | |
from shapely.geometry import box as bbox_to_polygon | |
from tqdm import tqdm | |
import rasterio | |
import rasterio.warp |
This file contains hidden or 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
from distutils.core import setup | |
from setuptools import find_packages | |
requirements = [r for r in open("requirements.txt", "r").read().splitlines() if not r.startswith("#")] | |
setup(name='MyPackage', | |
version='1.0', | |
description='Description of my package', | |
author='author-name', | |
author_email='author@email.com', |
This file contains hidden or 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
""" | |
This code will split the MyDataset class into a training set and a validation set, | |
using the train_test_split function from scikit-learn to generate the indices for | |
the training and validation sets. | |
The train_test_split function randomly splits the indices into two sets, | |
with the training set containing 80% of the data and the validation set containing the remaining 20%. | |
The training and validation sets are then created using the Subset class and wrapped in PyTorch DataLoaders, | |
which can be used to iterate over the datasets and feed the data into a PyTorch model during training and evaluation. | |
""" |
This file contains hidden or 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 sys | |
from pathlib import Path | |
# create absolute paths for this file and parents | |
__realpath__ = str(Path(os.path.realpath(__file__))) | |
__parents__ = [str(p) for p in Path(__realpath__).parents] | |
# add to PATH so that we can `import ...` | |
sys.path.append(__parents__[0]) |
This file contains hidden or 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 get_py_locals(filepath: str): | |
file_locals = {} | |
with open(filepath) as f: | |
content = f.read() | |
exec(content, None, file_locals) | |
return file_locals |