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 | |
import torch.nn.init as init | |
import torch.nn.functional as F | |
class _NonLocalBlockND(nn.Module): | |
def __init__(self, in_channels, inter_channels=None, dimension=3, sub_sample=True, bn_layer=True): | |
super(_NonLocalBlockND, self).__init__() | |
assert dimension in [1, 2, 3] |
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 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 |
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 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) |
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 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 |
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 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): |
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 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. |
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 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) | |
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 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") |
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
""" | |
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 |
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
""" | |
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 |
NewerOlder