/** * Load first model in model path as a {@link MLRegression} instance. */ private synchronized void loadModel() throws IOException { LOG.debug("Before loading model with memory {} in thread {}.", MemoryUtils.getRuntimeMemoryStats(), Thread .currentThread().getName()); long start = System.currentTimeMillis(); PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork()); FileSystem fs = ShifuFileUtils.getFileSystemBySourceType(SourceType.LOCAL); // load model from local d-cache model file model = (MLRegression) CommonUtils.loadModel(modelConfig, new Path("model0." + modelConfig.getAlgorithm().toLowerCase()), fs); LOG.debug("After load model class {} with time {}ms and memory {} in thread {}.", model.getClass().getName(), (System.currentTimeMillis() - start), MemoryUtils.getRuntimeMemoryStats(), Thread.currentThread() .getName()); }
/** * Save the specified object. * @param os The output stream to write to. * @param obj The object to save. */ public static void saveObject(final OutputStream os, final Object obj) { try { final EncogPersistor p = PersistorRegistry.getInstance() .getPersistor(obj.getClass()); if (p == null) { throw new PersistError("Do not know how to persist object: " + obj.getClass().getSimpleName()); } os.flush(); final PrintWriter pw = new PrintWriter(os); final Date now = new Date(); pw.println("encog," + obj.getClass().getSimpleName() + ",java," + Encog.VERSION + "," + p.getFileVersion() + "," + now.getTime()); pw.flush(); p.save(os, obj); } catch (final IOException ex) { throw new PersistError(ex); } }
PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork()); FSDataInputStream stream = null; BufferedReader br = null;
@SuppressWarnings("deprecation") public static List<ModelSpec> loadSubModels(ModelConfig modelConfig, List<ColumnConfig> columnConfigList, EvalConfig evalConfig, SourceType sourceType, Boolean gbtConvertToProb, String gbtScoreConvertStrategy) { List<ModelSpec> modelSpecs = new ArrayList<ModelSpec>(); FileSystem fs = ShifuFileUtils.getFileSystemBySourceType(sourceType); // we have to register PersistBasicFloatNetwork for loading such models PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork()); PathFinder pathFinder = new PathFinder(modelConfig); String modelsPath = null; if(evalConfig == null || StringUtils.isEmpty(evalConfig.getModelsPath())) { modelsPath = pathFinder.getModelsPath(sourceType); } else { modelsPath = evalConfig.getModelsPath(); } try { FileStatus[] fsArr = fs.listStatus(new Path(modelsPath)); for(FileStatus fileStatus: fsArr) { if(fileStatus.isDir()) { ModelSpec modelSpec = loadSubModelSpec(modelConfig, columnConfigList, fileStatus, sourceType, gbtConvertToProb, gbtScoreConvertStrategy); if(modelSpec != null) { modelSpecs.add(modelSpec); } } } } catch (IOException e) { log.error("Error occurred when loading sub-models.", e); } return modelSpecs; }
PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork());
/** * Load an object from an input stream. * @param is The input stream to read from. * @return The loaded object. */ public static Object loadObject(final InputStream is) { final String header = EncogDirectoryPersistence.readLine(is); final String[] params = header.split(","); if (!"encog".equals(params[0])) { throw new PersistError("Not a valid EG file."); } final String name = params[1]; final EncogPersistor p = PersistorRegistry.getInstance().getPersistor( name); if (p == null) { throw new PersistError("Do not know how to read the object: " + name); } if (p.getFileVersion() < Integer.parseInt(params[4])) { throw new PersistError( "The file you are trying to read is from a later version of Encog. Please upgrade Encog to read this file."); } return p.read(is); }
PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork());
public static List<FileStatus> locateBasicModels(ModelConfig modelConfig, EvalConfig evalConfig, SourceType sourceType) throws IOException { PersistorRegistry.getInstance().add(new PersistBasicFloatNetwork());