Skip to content

Instantly share code, notes, and snippets.

View p-geon's full-sized avatar
🕊️
pigeoning

Pigeon p-geon

🕊️
pigeoning
View GitHub Profile
import copy
import itertools
from typing import List, Callable
import numpy as np; np.random.seed(seed=42)
from sklearn.preprocessing import StandardScaler, minmax_scale
# https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler
# https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.minmax_scale.html#sklearn.preprocessing.minmax_scale
def check_result(y1, y2, eps=1e-11):
print(f'[y1] max: {np.round(np.max(y1), 4)}, min: {np.round(np.min(y1), 4)}, mean: {np.round(np.mean(y1), 4)}, std: {np.round(np.std(y1), 4)}')
print('tf.__version__', tf.__version__)
z_1 = [_*2 for _ in range(10)]
z_2 = [_*2+1 for _ in range(10)]
z_1 = tf.convert_to_tensor(z_1, dtype=tf.float32)
z_2 = tf.convert_to_tensor(z_2, dtype=tf.float32)
@tf.function
class AllVariablesNamePrinter:
def __init__(self):
self.a = 10
self.b = {
"ba": 1,
"bb": 2,
}
self.c = 20
def __call__(self):
! pip install -q termcolor==1.1.0
from termcolor import colored
print(colored('hello', 'red'), colored('world', 'green'))
print(colored("hello red world", 'red'))
# ---
red = "\x1b[31m"
red_ = "\x1b[0m"
print(f"{red}red{red_}a")
echo "[loading] ~/.zprofile"
# =========================================
## hook command: cd -> cd + ls
cdls ()
{
\cd "$@" && ls
}
# 色を使用
autoload -Uz colors
colors
# scp needs locate this
echo "[loading] ~/.zshrc"
# 補完
# autoload -Uz compinit
# compinit
from skimage import io
import matplotlib.pyplot as plt
def imshow(img, dpi=150):
if(len(img.shape)==2):#grayscale
plt.figure(dpi)
plt.imshow(img)
plt.gray()
plt.show()
else:
def unet(x, ch, depth, cut_path=False):
conv_kwargs = {'kernel_size': (3, 3), 'strides'=(1, 1), 'dilation_rate'=(1, 1),
'padding'='same', 'use_bias'=True, 'bias_initializer'='zeros', 'kernel_initializer'='he_normal'}
for _ in range(2):
x = tf.keras.layers.Convolution2D(ch, **conv_kwargs)(x)
x = tf.keras.layers.BatchNormalization()(x)
x = tf.keras.layers.Activation('relu')(x)
if(depth != 0):
path = x
touch Makefile
touch Dockerfile
touch .gitignore
touch .dockerignore
touch requirements.txt
# gigignore
echo '.ipynb_checkoints' >> .gitignore
echo '__pycache__' >> .gitignore
@p-geon
p-geon / python_utils.py
Last active May 14, 2021 09:08
python useful snippets
# for docker inside, "ls ./ && ls ../"
import os; print(os.listdir('./'), os.listdir('../'))
# =====
# images
# =====
'''read tif'''
!pip install tifffile==2020.9.3
import tifffile
tifffile.imread('filename.tif')