Skip to content

Instantly share code, notes, and snippets.

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
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
"""
Before running this cell, you will set hidden vars by "add-ons" menu.
"""
from kaggle_secrets import UserSecretsClient
def clone_repository(
ssh_keyval: "str: BEGIN RSA PRIVATE KEY to END RSA PRIVATE KEY"
, ssh_keyname: "str: id_rsa..."
, gitrepo: "str: your private repository to clone"
# curl -O https://gist.githubusercontent.com/xagano/1ba3caabd6d1c40d0fe85058a7294222/raw/b2ea3934cfeec110aaf74ca8f5bbdd07fae628fe/TF2_MNIST.py
import time
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
# resize
from skimage.io import imread, imsave
from skimage.transform import resize
x = imread("X.png")
x2 = resize(x, (128, 128))
imsave("resize.png", x2)
# overlay
from skimage.io import imread, imsave
from skimage.transform import resize
docker run --rm hello-world
FROM nvidia/cuda:9.0-cudnn7-runtime-ubuntu16.04
# Set anaconda(miniconda) path
ENV MINICONDA /opt/miniconda
ENV PATH $MINICONDA/bin:$PATH
# Download anaconda and install it
RUN apt-get update && apt-get install -y wget build-essential
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
from tqdm import tqdm
import numpy as np
from skimage.io import imread, imsave
win_h = win_w = 640
orig = imread(fname="image_A.png")
ours = imread(fname="image_B.png")
def main():
for i in tqdm(range(1)):
h_bias, w_bias = np.random.randint(0, orig.shape[0]-win_h), np.random.randint(0, orig.shape[1]-win_w)
crop_orig = orig[h_bias:h_bias+win_h, w_bias:w_bias+win_w]
GPUconfig = tf.ConfigProto(
gpu_options=tf.GPUOptions(
allow_growth=True
, visible_device_list="0"
)
, device_count={"GPU":1}
)
with tf.Session(graph=graph, config=GPUconfig) as sess:
print(sess.run())
import numpy as np
print("range: ", np.max(X[0]), np.min(X[0]))