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 | |
import matplotlib.pyplot as plt | |
import cv2 | |
import random | |
img = cv2.imread('img.jpg') | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
def concat_tile(im_list_2d): |
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
# matplotlibで画像として保存する | |
# 凡例をいい具合に枠外に持ってきた上で | |
# saveした時に見切れない様に調整 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
x = np.linspace(0, 4*math.pi, 100) | |
sin = np.sin(x) | |
cos = np.cos(x) |
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 | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
from sklearn.metrics import confusion_matrix | |
from sklearn.utils.multiclass import unique_labels | |
def plot_confusion_matrix(y_true, y_pred, | |
save_path, | |
normalize=True, |
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 | |
import scipy as sp | |
from functools import partial | |
from sklearn.metrics import cohen_kappa_score | |
def quadratic_weighted_kappa(y_hat, y): | |
return cohen_kappa_score(y_hat, y, weights='quadratic') | |
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 torch | |
import torch.nn as nn | |
from torch.nn import functional as F | |
class FocalLoss(nn.Module): | |
def __init__(self, alpha=1, gamma=2, logits=True, reduce=True): | |
super(FocalLoss, self).__init__() | |
self.alpha = alpha | |
self.gamma = gamma |
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 math | |
import random | |
from albumentations.core.transforms_interface import ImageOnlyTransform | |
class RandomShadow(ImageOnlyTransform): | |
def __init__(self, always_apply=False, p=0.5, sl=0.02, sh=0.4, r1=0.3, brightness=0.75): | |
super(RandomShadow, self).__init__(always_apply=always_apply, p=p) | |
self.brightness = brightness | |
self.sl = sl |
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
// Promise, async/awaitを使えば簡単にかける | |
/** | |
* msec: スリープさせる時間(秒) | |
* 戻り値はPromise | |
*/ | |
const sleep = (msec) => new Promise(resolve => setTimeout(resolve, msec * 1000)); | |
/** | |
* async/awaitでスリープ機能を実装 |
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
print("{}{: >25}{}{: >10}{}".format('|', 'Variable Name', '|', 'Memory', '|')) | |
print(" ------------------------------------ ") | |
for var_name in dir(): | |
if not var_name.startswith("_") and sys.getsizeof(eval(var_name)) > 10000: | |
print("{}{: >25}{}{: >10}{}{: >5}{}".format( | |
'|', var_name, '|', sys.getsizeof(eval(var_name)), '|', sys.getrefcount(var_name), '|')) |
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 make_logger(path: str) -> logging.Logger: | |
logger = logging.getLogger(__name__) # ロガーを取得 | |
logger.setLevel(logging.DEBUG) # 出力レベルを設定 | |
# 呼び出し元が異なる際に起こるloggerの重複を防ぐ | |
if not logger.hasHandlers(): | |
fmt = logging.Formatter( | |
'[%(levelname)s] - %(asctime)s - %(message)s' | |
) # フォーマッターを設定 | |
handler_s = logging.StreamHandler() # ストリームハンドラーを生成(標準出力) |
OlderNewer