use of org.vitrivr.cineast.core.data.SemanticMap in project cineast by vitrivr.
the class ConceptMasks method getSimilar.
@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
Optional<SemanticMap> optional = sc.getSemanticMap();
if (!optional.isPresent()) {
return Collections.emptyList();
}
DeepLabLabel[][] labels = optional.get().getLabels();
List<DeepLabLabel> list = linearize(labels);
ArrayList<LinkedList<DeepLabLabel>> partitions = GridPartitioner.partition(list, labels.length, labels[0].length, GRID_PARTITIONS, GRID_PARTITIONS);
float[] vector = new float[2 * GRID_PARTITIONS * GRID_PARTITIONS];
float[] weights = new float[2 * GRID_PARTITIONS * GRID_PARTITIONS];
for (int i = 0; i < GRID_PARTITIONS * GRID_PARTITIONS; ++i) {
DeepLabLabel dominantLabel = DeepLabLabel.getDominantLabel(partitions.get(i));
// TODO expose this to the API
float weight = dominantLabel == DeepLabLabel.NOTHING ? 0f : 1f;
weights[2 * i] = weight;
weights[2 * i + 1] = weight;
vector[2 * i] = dominantLabel.getEmbeddX();
vector[2 * i + 1] = dominantLabel.getEmbeddY();
}
return this.getSimilar(vector, new QueryConfig(qc).setDistanceWeights(weights));
}
use of org.vitrivr.cineast.core.data.SemanticMap in project cineast by vitrivr.
the class ConceptMasksAde20k method getSimilar.
@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
Optional<SemanticMap> optional = sc.getSemanticMap();
if (!optional.isPresent()) {
return Collections.emptyList();
}
DeepLabLabel[][] labels = optional.get().getLabels();
List<DeepLabLabel> list = linearize(labels);
ArrayList<LinkedList<DeepLabLabel>> ade20kPartitions = GridPartitioner.partition(list, labels.length, labels[0].length, GRID_PARTITIONS, GRID_PARTITIONS);
float[] vector = new float[2 * GRID_PARTITIONS * GRID_PARTITIONS];
float[] weights = new float[2 * GRID_PARTITIONS * GRID_PARTITIONS];
for (int i = 0; i < GRID_PARTITIONS * GRID_PARTITIONS; ++i) {
DeepLabLabel dominantLabel = DeepLabLabel.getDominantLabel(ade20kPartitions.get(i));
// TODO expose this to the API
float weight = dominantLabel == DeepLabLabel.NOTHING ? 0f : 1f;
weights[2 * i] = weight;
weights[2 * i + 1] = weight;
vector[2 * i] = dominantLabel.getEmbeddX();
vector[2 * i + 1] = dominantLabel.getEmbeddY();
}
return this.getSimilar(vector, new QueryConfig(qc).setDistanceWeights(weights));
}
Aggregations