use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.
the class ModelLoader method loadToDoubleArrays.
/**
* Load dense double model to a 2-dimension double array
*
* @param modelDir model save directory path
* @return model data
*/
public static double[][] loadToDoubleArrays(String modelDir, Configuration conf) throws IOException {
// Load model meta
MatrixFilesMeta meta = getMeta(modelDir, conf);
RowType rowType = RowType.valueOf(meta.getRowType());
// Check row type
if (rowType != RowType.T_DOUBLE_DENSE && rowType != RowType.T_DOUBLE_DENSE_COMPONENT) {
throw new IOException("model row type is not dense double, you should check it");
}
// Load model
DenseDoubleModel model = new DenseDoubleModel(meta.getRow(), meta.getCol());
loadModel(modelDir, model, meta, conf);
return model.getModel();
}
use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.
the class ModelLoader method loadToDoubleMaps.
/**
* Load dense double model to int->double maps
*
* @param modelDir model save directory path
* @return model data
*/
public static Int2DoubleOpenHashMap[] loadToDoubleMaps(String modelDir, Configuration conf) throws IOException {
// Load model meta
MatrixFilesMeta meta = getMeta(modelDir, conf);
RowType rowType = RowType.valueOf(meta.getRowType());
// Check row type
if (rowType != RowType.T_DOUBLE_SPARSE && rowType != RowType.T_DOUBLE_SPARSE_COMPONENT) {
throw new IOException("model row type is not sparse double, you should check it");
}
// Load model
SparseDoubleModel model = new SparseDoubleModel(meta.getRow(), meta.getCol());
loadModel(modelDir, model, meta, conf);
return model.getModel();
}
use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.
the class ModelLoader method loadToIntArrays.
/**
* Load dense float model to a 2-dimension int array
*
* @param modelDir model save directory path
* @return model data
*/
public static int[][] loadToIntArrays(String modelDir, Configuration conf) throws IOException {
// Load model meta
MatrixFilesMeta meta = getMeta(modelDir, conf);
RowType rowType = RowType.valueOf(meta.getRowType());
// Check row type
if (rowType != RowType.T_INT_DENSE && rowType != RowType.T_INT_DENSE_COMPONENT) {
throw new IOException("model row type is not dense int, you should check it");
}
// Load model
DenseIntModel model = new DenseIntModel(meta.getRow(), meta.getCol());
loadModel(modelDir, model, meta, conf);
return model.getModel();
}
use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.
the class ModelLoader method getMeta.
/**
* Get model meta
*
* @param modelDir model save directory path
* @return model meta
*/
public static MatrixFilesMeta getMeta(String modelDir, Configuration conf) throws IOException {
Path modelPath = new Path(modelDir);
Path meteFilePath = new Path(modelPath, ModelFilesConstent.modelMetaFileName);
MatrixFilesMeta meta = new MatrixFilesMeta();
FileSystem fs = meteFilePath.getFileSystem(conf);
if (!fs.exists(meteFilePath)) {
throw new IOException("matrix meta file does not exist ");
}
FSDataInputStream input = fs.open(meteFilePath);
meta.read(input);
input.close();
return meta;
}
use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.
the class ModelLoader method loadToDoubleLongKeyMaps.
/**
* Load dense double model to long->double maps
*
* @param modelDir model save directory path
* @return model data
*/
public static Long2DoubleOpenHashMap[] loadToDoubleLongKeyMaps(String modelDir, Configuration conf) throws IOException {
// Load model meta
MatrixFilesMeta meta = getMeta(modelDir, conf);
RowType rowType = RowType.valueOf(meta.getRowType());
// Check row type
if (rowType != RowType.T_DOUBLE_SPARSE_LONGKEY && rowType != RowType.T_DOUBLE_SPARSE_LONGKEY_COMPONENT) {
throw new IOException("model row type is not sparse long double, you should check it");
}
// Load model
SparseDoubleLongKeyModel model = new SparseDoubleLongKeyModel(meta.getRow(), meta.getCol());
loadModel(modelDir, model, meta, conf);
return model.getModel();
}
Aggregations