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 classifier(input_shape, kernel_size, pool_size): | |
model = Sequential() | |
model.add(Convolution3D(16, kernel_size=kernel_size, | |
padding='valid', | |
input_shape=input_shape)) | |
model.add(Activation('relu')) | |
model.add(MaxPooling3D(pool_size=pool_size)) | |
model.add(Convolution3D(32, kernel_size=kernel_size)) | |
model.add(Activation('relu')) |
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 qupath.lib.scripting.QP | |
import qupath.lib.geom.Point2 | |
import qupath.lib.roi.PolygonROI | |
import qupath.lib.objects.PathAnnotationObject | |
import qupath.lib.images.servers.ImageServer | |
//Aperio Image Scope displays images in a different orientation | |
def rotated = false |
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
# Importing core libraries | |
import numpy as np | |
import pandas as pd | |
from time import time | |
import pprint | |
import joblib | |
# Suppressing warnings because of skopt verbosity | |
import warnings | |
warnings.filterwarnings("ignore") |
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 lightgbm as lgb | |
import numpy as np | |
from sklearn.model_selection import train_test_split, GridSearchCV | |
from sklearn.model_selection import StratifiedKFold | |
from sklearn.metrics import accuracy_score, auc, roc_auc_score | |
import datetime | |
import argparse | |
import pickle | |
import data_loader | |
import warnings |
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
fuser -v /dev/nvidia* |awk '{for(i=1;i<=NF;i++)print "kill -9 " $i;}' | sh |
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
from keras.utils.data_utils import OrderedEnqueuer | |
val_generator = DataGenerator(target=target, dataset_type='test', batch_size=12, | |
dim=img_dim, shuffle=False) | |
steps_per_epoch = len(val_generator) | |
val_enqueuer = OrderedEnqueuer( | |
val_generator, | |
use_multiprocessing=use_multiprocessing) | |
val_enqueuer.start(workers=workers, | |
max_queue_size=max_queue_size) | |
val_enqueuer_gen = val_enqueuer.get() # 无限循环 ref:https://github.com/keras-team/keras/blob/master/keras/engine/training_generator.py#L180 |
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 subprocess, re | |
# Nvidia-smi GPU memory parsing. | |
# Tested on nvidia-smi 370.23 | |
def run_command(cmd): | |
"""Run command, return output as string.""" | |
output = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).communicate()[0] | |
return output.decode("ascii") |
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 | |
def pretty_print(header,col, data, file=sys.stdout): | |
row_format ="{:<40}" + "{:<15}" * (len(header)) # format | |
print(row_format.format("", *header), file=file) # print header | |
for team, row in zip(col, data): # print data part | |
print(row_format.format(team, *row),file=file) | |
print('-' * (40 + 15 * len(header)), file=file) # print end line |
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 hist_match(source, template): | |
""" | |
Adjust the pixel values of a grayscale image such that its histogram | |
matches that of a target image | |
Arguments: | |
----------- | |
source: np.ndarray | |
Image to transform; the histogram is computed over the flattened | |
array |
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 keras | |
class DataGenerator(keras.utils.Sequence): | |
'Generates data for Keras' | |
def __init__(self, list_IDs, labels, batch_size=32, dim=(32,32,32), n_channels=1, | |
n_classes=10, shuffle=True): | |
'Initialization' | |
self.dim = dim | |
self.batch_size = batch_size |
OlderNewer