def save_models_to_disk_static(top_model, root, new_name): top_model.model = lm(root + '{}.h5'.format(new_name)) top_model.inf_encoder_model = lm(root + '{}_inf_encoder.h5'.format(new_name)) top_model.inf_intent_classifier = lm( root + '{}_inf_intent.h5'.format(new_name)) top_model.inf_decoder_model = lm(root + '{}_inf_decoder.h5'.format(new_name))
def load_models_from_disk(self, root, new_name): # self.model = lm(root + '{}.h5'.format(new_name)) self.inf_encoder_model = lm(root + '{}_inf_encoder.h5'.format(new_name)) self.inf_intent_classifier = lm(root + '{}_inf_intent.h5'.format(new_name)) self.inf_decoder_model = lm(root + '{}_inf_decoder.h5'.format(new_name))
def load_model(model_path): """Loads the model using a json description of the model and a hdf file containing the weights. Args: model_path: path to the model.h5 file. Returns: model: model object """ return lm(model_path)
from PIL import Image as im def open(p: str) -> np.ndarray: img = im.open(os.path.join(path, p)).convert('L') (width, height) = img.size if width > 28 and height > 28: img = img.resize((28, 28), im.ANTIALIAS) else: pass (width, height) = img.size img = list(img.getdata()) img = np.array(img) img = img.reshape((height, width)) return img def norm(x: np.ndarray): ret = x / 255 ret = np.expand_dims(ret, axis=0) ret = np.expand_dims(ret, axis=3) return ret model = lm('IRC_MNIST.h5') img = open('MyTestNum1.png') img = norm(img) res = model.predict(img) print(f"Розпізнана цифра: {np.argmax(res)}")
def load_model_2(self, path): # self.sess = tf.Session() # with self.sess.as_default(): # # backend.set_session(self.sess) with CustomObjectScope({'GlorotUniform': glorot_uniform()}): return lm(path)
# frame['eventid'] = dataclasses.I3VectorDouble(eventid) # frame['TCN'] = dataclasses.I3VectorDouble(prediction_vector) # frame['truth'] = dataclasses.I3VectorDouble(truth_vector) def savefeatures(frame, fin=None, names=None): for i, name in enumerate(names): fin[i].append(frame[name]) use_truth = 1 #Tensorflow stuff if use_truth == 0: from tensorflow.keras.models import load_model as lm model = lm( '/home/sstray/test/condor/corsikafiles/corsika_model_test/classification_model' ) # import os from I3Tray import * from icecube import dataio from icecube import dataclasses from icecube import simclasses from icecube import recclasses import numpy as np #import cProfile, pstats, StringIO import argparse import matplotlib.path as mpath bordercoords = np.array([(-256.1400146484375, -521.0800170898438), (-132.8000030517578, -501.45001220703125), (-9.13000011444092, -481.739990234375),
parser.add_argument('-rad','--radius') parser.add_argument('-th','--threshold') args = parser.parse_args() if args.radius: rad = args.radius else: rad = 75 print('No radius supplied. Will default to 75') if args.threshold: th = args.threshold else: th = 0.9 print('No threshold supplied. Will default to 0.9') meanstd = np.loadtxt('/home/sstray/test/condor/singu/meanstd.txt') model = lm('/home/sstray/test/condor/singu/my_model/classification_model') def get_groups(features_in,event_in): features = features_in eventnum = event_in grouped_features = ([features[np.isin(eventnum,[i])] for i in np.unique(eventnum)]) grouped_features = [np.vstack((np.array(i),np.zeros((100,features.shape[1]))))[:100] for i in grouped_features if len(i)<100 if len(i)>10] grouped_features = np.dstack(grouped_features) grouped_features = np.rollaxis(grouped_features,2,0) return grouped_features filelist = args.infiles.split(',') print(filelist) for nums in range(len(filelist)): hf = h5py.File(filelist[nums],'r')