Skip to content

Instantly share code, notes, and snippets.

View jimmy15923's full-sized avatar

Cheng-Kun Yang jimmy15923

View GitHub Profile
import sys
sys.path.append("/data/jimmy15923/CGMH_NPC_PROGRAM/ndpi2dzi/") ## set path for ndpi
import ndpread
import json
import numpy as np
import pickle
import cv2
from matplotlib.path import Path
import json
import matplotlib.pyplot as plt
@jimmy15923
jimmy15923 / LMS_UM_test.py
Last active November 22, 2018 05:02
test code for IBM LMS
"""
Tesing code for IBM LMS / CUDA Unified Memory
Run this script with CUDA Unified Memory by
```
python LMS_UM_test.py --image_size=224 --batch_size=256 --gpu_id=1 --cuda_memory=5
```
Run this script with IBM Large Model Support
```
python LMS_UM_test.py --image_size=224 --batch_size=256 --gpu_id=1 --use_lms=True
"""
Tesing code for CUDA unified memory
Run this script with CUDA unified memory by
```
python cuda_unified_test.py --image_size=224 --batch_size=256 --gpu_id=1 --cuda_memory=5
```
"""
import numpy as np
import time
@jimmy15923
jimmy15923 / lms_keras.py
Last active January 18, 2019 07:21
keras code for IBM LMS testing
import numpy as np
import tensorflow as tf
import os
# FLAGS
tf.logging.set_verbosity(tf.logging.INFO)
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('f', '', 'kernel')
tf.app.flags.DEFINE_string("gpu_id", "0", "idx of GPU using")
tf.app.flags.DEFINE_integer("batch_size", 512, "Batch size")
import tensorflow as tf
import numpy as np
import six
def _bn_relu(input):
"""Helper to build a BN -> relu block (by @raghakot)."""
norm = tf.keras.layers.BatchNormalization(axis=CHANNEL_AXIS)(input)
return tf.keras.layers.Activation("relu")(norm) #Activation("relu")(norm)
def resize_image(image, min_dim=None, max_dim=None, min_scale=None, mode="square"):
"""Resizes an image keeping the aspect ratio unchanged.
min_dim: if provided, resizes the image such that it's smaller
dimension == min_dim
max_dim: if provided, ensures that the image longest side doesn't
exceed this value.
min_scale: if provided, ensure that the image is scaled up by at least
this percent even if min_dim doesn't require it.
mode: Resizing mode.
none: No resizing. Return the image unchanged.
import keras.layers as KL
import keras.engine as KE
import keras.models as KM
from keras.engine import Layer, InputSpec
from keras import initializers, regularizers, constraints
from keras import backend as K
from keras.utils.generic_utils import get_custom_objects
class BatchNorm(KL.BatchNormalization):
import tensorflow as tf
import keras
import keras.backend as K
import keras.layers as KL
import keras.engine as KE
import keras.models as KM
from keras.engine import Layer, InputSpec
from keras import initializers, regularizers, constraints
from keras import backend as K
def grad_cam(img, model):
"""Gradient Activation Map for keras model
# Arguments
img: image to plot gradcam
model: keras model
# Returns
gradcam image
"""
img = np.expand_dims(img, 0)
import sys
sys.path.append("/mnt/deep-learning/usr/jimmy15923/keras_rcnn_family")
import json
import numpy as np
from collections import Counter
from scipy.ndimage.measurements import label
from slide_reader import *
import glob
import matplotlib.pyplot as plt