Skip to content
Snippets Groups Projects
Commit 51eb2f8f authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Disable KDTree for now.

parent 2d25c746
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -58,7 +58,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors, final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors,
getCodebookSize(), getCodebookSize(),
options.getWorkerCount(), options.getWorkerCount(),
options.getQuantizationVector()); options.getQuantizationVector(),
true);
final LBGResult vqResult = vqInitializer.findOptimalCodebook(); final LBGResult vqResult = vqInitializer.findOptimalCodebook();
return new VectorQuantizer(vqResult.getCodebook()); return new VectorQuantizer(vqResult.getCodebook());
} }
...@@ -235,8 +236,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -235,8 +236,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @return Indices of codebook vectors. * @return Indices of codebook vectors.
*/ */
private int[] quantizeVectorsImpl(final VectorQuantizer quantizer, final int[][] srcVectors, final int workerCount) { private int[] quantizeVectorsImpl(final VectorQuantizer quantizer, final int[][] srcVectors, final int workerCount) {
if (useKdTree) // if (useKdTree)
return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount); // return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount);
return quantizer.quantizeIntoIndices(srcVectors, workerCount); return quantizer.quantizeIntoIndices(srcVectors, workerCount);
} }
...@@ -339,9 +340,17 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -339,9 +340,17 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData, final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData,
getCodebookSize(), getCodebookSize(),
options.getWorkerCount(), options.getWorkerCount(),
options.getQuantizationVector()); options.getQuantizationVector(),
false);
reportStatusToListeners("Starting LBG optimization."); reportStatusToListeners("Starting LBG optimization.");
try {
System.out.println("Sleeping for 10 seconds...");
Thread.sleep(10000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
vqInitializer.setStatusListener(this::reportStatusToListeners); vqInitializer.setStatusListener(this::reportStatusToListeners);
final LBGResult lbgResult = vqInitializer.findOptimalCodebook(); final LBGResult lbgResult = vqInitializer.findOptimalCodebook();
reportStatusToListeners("Learned the optimal codebook."); reportStatusToListeners("Learned the optimal codebook.");
...@@ -376,7 +385,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -376,7 +385,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer codebookTrainer = new LBGVectorQuantizer(trainingData, final LBGVectorQuantizer codebookTrainer = new LBGVectorQuantizer(trainingData,
256, 256,
options.getWorkerCount(), options.getWorkerCount(),
options.getQuantizationVector()); options.getQuantizationVector(),
false);
codebookTrainer.findOptimalCodebook(vqCodebook -> { codebookTrainer.findOptimalCodebook(vqCodebook -> {
try { try {
assert ((vqCodebook.getCodebookSize() == vqCodebook.getVectors().length) && assert ((vqCodebook.getCodebookSize() == vqCodebook.getVectors().length) &&
......
package cz.it4i.qcmp.quantization.vector; package cz.it4i.qcmp.quantization.vector;
import cz.it4i.qcmp.kdtree.KDTree;
import cz.it4i.qcmp.kdtree.KDTreeBuilder;
import cz.it4i.qcmp.utilities.Utils; import cz.it4i.qcmp.utilities.Utils;
public class VectorQuantizer { public class VectorQuantizer {
...@@ -15,14 +13,14 @@ public class VectorQuantizer { ...@@ -15,14 +13,14 @@ public class VectorQuantizer {
private final int vectorSize; private final int vectorSize;
private final long[] frequencies; private final long[] frequencies;
private final KDTree kdTree; // private final KDTree kdTree;
public VectorQuantizer(final VQCodebook codebook) { public VectorQuantizer(final VQCodebook codebook) {
this.codebookVectors = codebook.getVectors(); this.codebookVectors = codebook.getVectors();
this.vectorSize = codebook.getVectors()[0].length; this.vectorSize = codebook.getVectors()[0].length;
this.frequencies = codebook.getVectorFrequencies(); this.frequencies = codebook.getVectorFrequencies();
kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors()); // kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors());
} }
public int[] quantize(final int[] dataVector) { public int[] quantize(final int[] dataVector) {
...@@ -99,11 +97,11 @@ public class VectorQuantizer { ...@@ -99,11 +97,11 @@ public class VectorQuantizer {
return indices; return indices;
} }
public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) { // public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
//
return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) -> // return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) ->
kdTree.findNearestBBF(queryVector, 8)); // kdTree.findNearestBBF(queryVector, 8));
} // }
public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) { public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment