Skip to content

Instantly share code, notes, and snippets.

View seanswyi's full-sized avatar

Sean (Seok-Won) Yi seanswyi

View GitHub Profile
@seanswyi
seanswyi / .isort.cfg
Created June 4, 2023 21:35
Personal isort configuation file.
[settings]
multi_line_output=3
lines_after_imports=2
sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER
[tool.isort]
profile="black"
@seanswyi
seanswyi / .pre-commit-config.yaml
Last active June 4, 2023 21:36
Personal Pre-commit configuration file.
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# For Python 3.10.
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python3.10
- repo: https://github.com/asottile/add-trailing-comma
@seanswyi
seanswyi / add_img_extension.py
Created April 13, 2023 06:26
Adds file extensions to image files.
import argparse
from concurrent.futures import ProcessPoolExecutor
import multiprocessing as mp
import os
import numpy as np
from PIL import (
Image,
UnidentifiedImageError
)
import argparse
from concurrent.futures import ProcessPoolExecutor
import multiprocessing as mp
import os
import time
import boto3
import numpy as np
import pandas as pd
from tqdm import tqdm
@seanswyi
seanswyi / gpu_report.py
Created February 2, 2023 05:17
scikit-learn classification report style GPU report for CUDA.
import torch
def get_gpu_report():
device_ids = list(range(torch.cuda.device_count()))
device_names = [torch.cuda.get_device_name(id_) for id_ in device_ids]
mem_reserved = [torch.cuda.max_memory_reserved(id_) for id_ in device_ids]
mem_reserved_fmtd = [f'{mem / (1024 ** 3):.2f}' for mem in mem_reserved]
longest_name = max(len(name) for name in device_names)
@seanswyi
seanswyi / download_images.py
Last active March 6, 2023 01:41
Python script to download images from URLs based on a DataFrame and also save the paths to the images.
import argparse
from concurrent.futures import ProcessPoolExecutor
from datetime import datetime
import multiprocessing as mp
import os
import time
import numpy as np
import pandas as pd
import requests
@seanswyi
seanswyi / classification_report_output_pred.py
Created January 21, 2023 12:46
Scikit-Learn's classification_report modified to output number of predictions as well.
def precision_recall_fscore_support(
y_true,
y_pred,
*,
beta=1.0,
labels=None,
pos_label=1,
average=None,
warn_for=("precision", "recall", "f-score"),
sample_weight=None,
@seanswyi
seanswyi / medium_pytorch_cnn.py
Last active May 17, 2020 03:02
GitHub Gist for PyTorch CNN tutorial on Medium.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
# ================== Step 1: Basic configuration for the data. ================================
transform = transforms.Compose([transforms.ToTensor(),
@seanswyi
seanswyi / tensorflow_self_check.py
Created March 13, 2019 15:28 — forked from mrry/tensorflow_self_check.py
[DEPRECATED] TensorFlow on Windows self-check
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,