def load_parameters(self, params): reg_base64 = params.get('reg_base64', None) if reg_base64 is None: raise InvalidModelParamsException() reg_bytes = base64.b64decode(reg_base64.encode('utf-8')) self._reg = pickle.loads(reg_bytes)
def load_parameters(self, params): # Load model parameters clf_base64 = params['clf_base64'] if clf_base64 is None: raise InvalidModelParamsException() clf_bytes = base64.b64decode(clf_base64.encode('utf-8')) self._clf = pickle.loads(clf_bytes)
def load_parameters(self, params): # Load model parameters h5_model_base64 = params.get('h5_model_base64', None) if h5_model_base64 is None: raise InvalidModelParamsException() with tempfile.NamedTemporaryFile() as tmp: # Convert back to bytes & write to temp file h5_model_bytes = base64.b64decode(h5_model_base64.encode('utf-8')) with open(tmp.name, 'wb') as f: f.write(h5_model_bytes) # Load model from temp file with self._graph.as_default(): with self._sess.as_default(): self._model = keras.models.load_model(tmp.name)
def _build_classifier(self, n_estimators, min_child_weight, max_depth, gamma, subsample, colsample_bytree, num_class): if num_class < 2: raise InvalidModelParamsException() elif num_class == 2: clf = xgb.XGBClassifier(n_estimators=n_estimators, min_child_weight=min_child_weight, max_depth=max_depth, gamma=gamma, subsample=subsample, colsample_bytree=colsample_bytree) else: clf = xgb.XGBClassifier(n_estimators=n_estimators, min_child_weight=min_child_weight, max_depth=max_depth, gamma=gamma, subsample=subsample, colsample_bytree=colsample_bytree, objective='multi:softmax', num_class=num_class) return clf
def load_parameters(self, params): h5_model_base64 = params.get('h5_model_base64', None) if h5_model_base64 is None: raise InvalidModelParamsException() # TODO: Not save to & read from a file # Convert back to bytes & write to temp file tmp = tempfile.NamedTemporaryFile(delete=False) h5_model_bytes = base64.b64decode(h5_model_base64.encode('utf-8')) with open(tmp.name, 'wb') as f: f.write(h5_model_bytes) # Load model from temp file with self._graph.as_default(): with self._sess.as_default(): self._model = keras.models.load_model(tmp.name) # Remove temp file os.remove(tmp.name) if 'predict_label_mapping' in params: self._predict_label_mapping = params['predict_label_mapping']