Skip to content

Instantly share code, notes, and snippets.

View ResidentMario's full-sized avatar

Aleksey Bilogur ResidentMario

View GitHub Profile
import numpy as np
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.base import BaseEstimator
class KerasBatchClassifier(KerasClassifier, BaseEstimator):
def __init__(self, model, **kwargs):
super().__init__(model)
self.fit_kwargs = kwargs
self._estimator_type = 'classifier'
from keras.wrappers.scikit_learn import KerasClassifier
# notice how we go back to stating hyperparameters at init time
# this is the "scikit-learn" way
model = KerasClassifier(
twoLayerFeedForward, epochs=100, batch_size=500, verbose=0
)
# now fit and predict
model.fit(X, y)
# import model base and layers
from keras.models import Sequential
from keras.layers import Dense
def twoLayerFeedForward():
# stack the layers
clf = Sequential()
clf.add(Dense(9, activation='relu', input_dim=3))
clf.add(Dense(9, activation='relu'))
clf.add(Dense(3, activation='softmax'))
# import a classifier object
from sklearn.svm import LinearSVC
# initialize it with hyperparameters
clf = LinearSVC(penalty='l2', loss='hinge')
# call fit on data to train the model
clf.fit(X, y)
# call predict to get predictions
from t4 import list_packages, Package
MODULE_PATH = []
class DataPackageImporter:
"""
Data package module loader. Executes package import code and adds the package to the
module cache.
"""
from importlib.machinery import ModuleSpec
class DataPackageFinder:
"""
Data package module loader finder. This class sits on `sys.meta_path` and returns the
loader it knows for a given path, if it knows a compatible loader.
"""
@classmethod
def find_spec(cls, fullname, path=None, target=None):
import pathlib
sample_size = len(list(pathlib.Path('../data/images_cropped/').rglob('./*')))
batch_size = 16
hist = model.fit_generator(
train_generator,
steps_per_epoch=sample_size // batch_size,
epochs=50,
validation_data=validation_generator,
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras.losses import binary_crossentropy
from keras.callbacks import EarlyStopping
from keras.optimizers import RMSprop
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), input_shape=(128, 128, 3), activation='relu'))
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1/255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
import sys
import os
import pandas as pd
import requests
from tqdm import tqdm
import ratelim
from checkpoints import checkpoints
checkpoints.enable()