Skip to content

Instantly share code, notes, and snippets.

View steermomo's full-sized avatar
🏠
Working from home

HangL steermomo

🏠
Working from home
View GitHub Profile
@steermomo
steermomo / example.py
Created April 15, 2018 12:33
Keras TypeError: max_pool3d() got an unexpected keyword argument 'data_format'
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'))
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
# 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")
@steermomo
steermomo / tuning_lightgbm.py
Created March 12, 2019 03:24
BayesianOptimization lightgbm
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
fuser -v /dev/nvidia* |awk '{for(i=1;i<=NF;i++)print "kill -9 " $i;}' | sh
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
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")
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
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
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