def load_model(): global lookupDF global song_file_map global column_maps global max_list global model global scaler global graph global probDF # Load model model = nn.load_model('./model/working/std') graph = tf.get_default_graph() # Load preprocessing dependencies with open('./data/song-file-map.json', 'r') as f: song_file_map = json.load(f) with open('./model/working/preprocessing/maps.json', 'r') as f: column_maps = json.load(f) with open('./model/working/preprocessing/max_list.json', 'r') as f: max_list = json.load(f) scaler = joblib.load('./model/working/preprocessing/robust.scaler') # Load song ID lookup for frontend lookupDF = pd.read_hdf('./frontend/data/lookup.h5', 'df') # Model predictions for comparison probDF = pd.read_pickle('./data/model_prob.pkl')
def main(): nn.load_model() while True: sound_byte = se.stream() nn.decide(sound_byte)
#!/usr/bin/env python3 import sys import torch import numpy as np from neural_net import load_model from data import train_selector, test_selector1, test_selector2, load_images np.random.seed(0) torch.manual_seed(0) net = load_model(sys.argv[1]) images = [] for selector in (train_selector, test_selector1, test_selector2): images += load_images(selector, max_per_class=1)[0] batch = net(torch.cat(images, dim=0)) transpose = batch.t() norms = transpose.pow(2).sum(dim=1).clamp(min=0.001).sqrt() norm_mat = norms.unsqueeze(0) * norms.unsqueeze(1) redundancy = ((transpose @ batch) / norm_mat).abs().mean() print("redudancy", redundancy)
from flask import Flask, render_template, request, jsonify import base64 from PIL import Image from neural_net import make_guess, load_model, Net # Model Download: https://mega.nz/#!YU8l2ChT!VEKIfNNfL7fAfoRmKFJhU7K__XTTJw2GLOUTBkFVOX8 # Once downloaded, extract the .pth file to ml/models/ folder MODEL_NAME = 'trained_model_49.pth' # The name of your model as found in ml/models/ folder app = Flask(__name__) # Create and load pre-trained neural network net = Net(total_classes=49) load_model(net, path='ml/models/{}'.format(MODEL_NAME)) def convert_image(image_path): img = Image.open(image_path) img.load() background = Image.new("RGB", img.size, (255, 255, 255)) background.paste(img, mask=img.split()[3]) background.save(image_path, 'PNG') fin = Image.open(image_path) out = Image.new("RGB", img.size, (255, 255, 255)) width, height = fin.size for x in range(width): for y in range(height): r, g, b = fin.getpixel((x, y)) if r == g == b: