本文整理了Java中org.openimaj.io.IOUtils
类的一些代码示例,展示了IOUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils
类的具体详情如下:
包路径:org.openimaj.io.IOUtils
类名称:IOUtils
[英]Methods for reading Readable objects and writing Writeable objects.
[中]读取可读对象和写入可写对象的方法。
代码示例来源:origin: openimaj/openimaj
@Override
public void readBinary(DataInput in) throws IOException {
final LazyFaceRecogniser<FACE, PERSON, EXTRACTOR> wrapper = IOUtils.read(in);
this.extractor = wrapper.extractor;
this.faceCache = wrapper.faceCache;
this.internalRecogniser = wrapper.internalRecogniser;
this.isInvalid = wrapper.isInvalid;
}
代码示例来源:origin: org.openimaj.tools/GlobalFeaturesTool
void execute() throws IOException {
FeatureVector fv = featureOp.extract(input);
if (binary)
IOUtils.writeBinary(output, fv);
else
IOUtils.writeASCII(output, fv);
}
代码示例来源:origin: openimaj/openimaj
/**
* Write this {@link VLADIndexerData} object to the given file. The file can
* be re-read using the {@link #read(File)} method.
*
* @param file
* the file to write to
* @throws IOException
* if an error occurs
*/
public void write(File file) throws IOException {
IOUtils.writeToFile(this, file);
}
代码示例来源:origin: openimaj/openimaj
private FEATURE write(FEATURE feature, File cachedFeature) throws IOException {
if (feature instanceof WriteableBinary) {
IOUtils.writeBinaryFull(cachedFeature, (WriteableBinary) feature);
} else {
IOUtils.writeToFile(feature, cachedFeature);
}
return feature;
}
代码示例来源:origin: openimaj/openimaj
@SuppressWarnings("unchecked")
private FEATURE load(File cachedFeature) {
try {
return (FEATURE) IOUtils.read(cachedFeature);
} catch (final Exception e) {
try {
return (FEATURE) IOUtils.readFromFile(cachedFeature);
} catch (final IOException e1) {
logger.warn("Error reading from cache. Feature will be regenerated.");
}
}
return null;
}
代码示例来源:origin: openimaj/openimaj
/**
* Convenience function for serializing a writeable object as a byte array.
* Calls {@link IOUtils#writeBinary(OutputStream, WriteableBinary)} on a
* {@link ByteArrayOutputStream} then calls
* {@link ByteArrayOutputStream#toByteArray()}
*
* @param object
* @return serialised object
* @throws IOException
*/
public static byte[] serialize(WriteableBinary object) throws IOException {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
IOUtils.writeBinary(stream, object);
return stream.toByteArray();
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
protected void reduce(LongWritable key, Iterable<BytesWritable> values,
Reducer<LongWritable, BytesWritable, LongWritable, BytesWritable>.Context context) throws IOException,
InterruptedException
{
final TweetCountWordMap accum = new TweetCountWordMap();
for (final BytesWritable tweetwordmapbytes : values) {
TweetCountWordMap tweetwordmap = null;
tweetwordmap = IOUtils.read(new ByteArrayInputStream(tweetwordmapbytes.getBytes()),
TweetCountWordMap.class);
accum.combine(tweetwordmap);
}
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
IOUtils.writeBinary(outstream, accum);
context.write(key, new BytesWritable(outstream.toByteArray()));
}
}
代码示例来源:origin: openimaj/openimaj
@Override
protected Eigenvalues spectralCluster(SparseMatrix data) {
Eigenvalues eig = null;
if(cache.exists()){
logger.debug("Loading eigenvectors from cache");
try {
eig = IOUtils.readFromFile(cache);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else{
// Compute the laplacian of the graph
logger.debug("Cache empty, recreating eigenvectors");
final SparseMatrix laplacian = laplacian(data);
eig = laplacianEigenVectors(laplacian);
try {
logger.debug("Writing eigenvectors to cache");
IOUtils.writeToFile(eig, cache);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return eig;
}
代码示例来源:origin: openimaj/openimaj
public static void createPQADCNN() throws IOException {
final File input = new File("/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x.dat");
final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(input)));
final VLADIndexerData indexer = VLADIndexerData.read(new File(
"/Users/jsh2/vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x.dat"));
final IncrementalFloatADCNearestNeighbours nn = new IncrementalFloatADCNearestNeighbours(
indexer.getProductQuantiser(), 128,
46000000);
final TLongArrayList indexes = new TLongArrayList(46000000);
try {
final float[] farr = new float[128];
for (int x = 0;; x++) {
if (x % 100000 == 0)
System.out.println(x);
final long id = dis.readLong();
for (int i = 0; i < 128; i++) {
farr[i] = dis.readFloat();
}
nn.add(farr);
indexes.add(id);
}
} catch (final EOFException e) {
dis.close();
}
IOUtils.writeBinary(new File(
"/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x-pqadcnn.dat"), nn);
IOUtils.writeToFile(indexes, new File(
"/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x-pqadcnn-indexes.dat"));
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
public String toString() {
StringWriter writer = new StringWriter();
try {
IOUtils.writeASCII(writer, this);
} catch (IOException e) {
return "ERRORSTRING";
}
return writer.toString();
}
代码示例来源:origin: openimaj/openimaj
@Override
public void writeBinary(DataOutput out) throws IOException {
IOUtils.write(comp, out);
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void reduce(Text word, java.lang.Iterable<BytesWritable> dfidfs, Reducer<Text,BytesWritable,NullWritable,Text>.Context context) throws java.io.IOException ,InterruptedException {
WordDFIDFTimeSeries dts = new WordDFIDFTimeSeries();
for (BytesWritable bytesWritable : dfidfs) {
WordDFIDF wd = IOUtils.deserialize(bytesWritable.getBytes(), WordDFIDF.class);
dts.add(wd.timeperiod, wd);
}
StringWriter writer = new StringWriter();
writer.write(word + " ");
IOUtils.writeASCII(writer, dts);
context.write(NullWritable.get(), new Text(writer .toString()));
};
}
代码示例来源:origin: openimaj/openimaj
/**
* Read a {@link VLADIndexerData} object to the given file created with the
* {@link #write(File)} method.
*
* @param file
* the file to read from
* @return the newly read {@link VLADIndexerData} object.
* @throws IOException
* if an error occurs
*/
public static VLADIndexerData read(File file) throws IOException {
return IOUtils.readFromFile(file);
}
代码示例来源:origin: openimaj/openimaj
private void replaceSequenceFileWithCluster(String sequenceFile, ByteCentroidsResult cluster) throws IOException {
final Path p = new Path(sequenceFile);
final FileSystem fs = HadoopFastKMeansOptions.getFileSystem(p.toUri());
fs.delete(p, true); // Delete the sequence file of this name
FSDataOutputStream stream = null;
try {
stream = fs.create(p);
IOUtils.writeBinary(stream, cluster); // Write the cluster
} finally {
if (stream != null)
stream.close();
}
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void reduce(LongWritable key, Iterable<BytesWritable> values,
Reducer<LongWritable, BytesWritable, LongWritable, BytesWritable>.Context context) throws IOException,
InterruptedException
{
final TweetCountWordMap accum = new TweetCountWordMap();
for (final BytesWritable tweetwordmapbytes : values) {
TweetCountWordMap tweetwordmap = null;
tweetwordmap = IOUtils.read(new ByteArrayInputStream(tweetwordmapbytes.getBytes()),
TweetCountWordMap.class);
accum.combine(tweetwordmap);
}
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
IOUtils.writeBinary(outstream, accum);
context.write(key, new BytesWritable(outstream.toByteArray()));
}
}
代码示例来源:origin: openimaj/openimaj
final MixtureOfGaussians gmm = IOUtils.readFromFile(new File(
"/Volumes/Raid/face_databases/lfw-centre-affine-pdsift-pca64-augm-gmm512.bin"));
final FisherVector<float[]> fisher = new FisherVector<float[]>(gmm, true, true);
IOUtils.writeToFile(fisher, new File(
"/Volumes/Raid/face_databases/lfw-centre-affine-pdsift-pca64-augm-gmm512-fisher.bin"));
代码示例来源:origin: org.openimaj/core-feature
@SuppressWarnings("unchecked")
private FEATURE load(File cachedFeature) {
try {
return (FEATURE) IOUtils.read(cachedFeature);
} catch (final Exception e) {
try {
return (FEATURE) IOUtils.readFromFile(cachedFeature);
} catch (final IOException e1) {
logger.warn("Error reading from cache. Feature will be regenerated.");
}
}
return null;
}
代码示例来源:origin: org.openimaj/sandbox
public static void createPQADCNN() throws IOException {
final File input = new File("/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x.dat");
final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(input)));
final VLADIndexerData indexer = VLADIndexerData.read(new File(
"/Users/jsh2/vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x.dat"));
final IncrementalFloatADCNearestNeighbours nn = new IncrementalFloatADCNearestNeighbours(
indexer.getProductQuantiser(), 128,
46000000);
final TLongArrayList indexes = new TLongArrayList(46000000);
try {
final float[] farr = new float[128];
for (int x = 0;; x++) {
if (x % 100000 == 0)
System.out.println(x);
final long id = dis.readLong();
for (int i = 0; i < 128; i++) {
farr[i] = dis.readFloat();
}
nn.add(farr);
indexes.add(id);
}
} catch (final EOFException e) {
dis.close();
}
IOUtils.writeBinary(new File(
"/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x-pqadcnn.dat"), nn);
IOUtils.writeToFile(indexes, new File(
"/Volumes/My Book/flickr46m-vlad64-pca128-pq16x8-indexer-mirflickr25k-sift1x-pqadcnn-indexes.dat"));
}
代码示例来源:origin: openimaj/openimaj
@Override
public String toString() {
StringWriter writer = new StringWriter();
try {
IOUtils.writeASCII(writer, this);
} catch (IOException e) {
return "ERRORSTRING";
}
return writer.toString();
}
代码示例来源:origin: openimaj/openimaj
@Override
public void writeBinary(DataOutput out) throws IOException {
IOUtils.write(config, out);
}
内容来源于网络,如有侵权,请联系作者删除!