Search in sources :

Example 16 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class VisualTextCoEmbedding method getSimilar.

@Override
public List<ScoreElement> getSimilar(String segmentId, ReadableQueryConfig qc) {
    // Ensure the correct distance function is used
    QueryConfig queryConfig = QueryConfig.clone(qc);
    queryConfig.setDistance(DISTANCE);
    return super.getSimilar(segmentId, queryConfig);
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig)

Example 17 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class CLIPImage method getSimilar.

@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
    if (sc.getMostRepresentativeFrame() == VideoFrame.EMPTY_VIDEO_FRAME) {
        return Collections.emptyList();
    }
    QueryConfig queryConfig = QueryConfig.clone(qc);
    queryConfig.setDistance(DISTANCE);
    float[] embeddingArray = embedImage(sc.getMostRepresentativeFrame().getImage().getBufferedImage());
    return getSimilar(embeddingArray, queryConfig);
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig)

Example 18 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig 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));
}
Also used : DeepLabLabel(org.vitrivr.cineast.core.features.neuralnet.tf.models.deeplab.DeepLabLabel) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) SemanticMap(org.vitrivr.cineast.core.data.SemanticMap) LinkedList(java.util.LinkedList)

Example 19 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class AverageColorRaster method getSimilar.

private List<ScoreElement> getSimilar(float[] raster, float[] hist, ReadableQueryConfig rqc) {
    final int limit = rqc.getResultsPerModule();
    final QueryConfig qc = new QueryConfig(rqc).setDistanceIfEmpty(Distance.chisquared);
    List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getNearestNeighbourRows(limit * 5, hist, "hist", qc);
    ArrayList<ScoreElement> scores = new ArrayList<>(rows.size());
    for (Map<String, PrimitiveTypeProvider> map : rows) {
        String id = map.get(GENERIC_ID_COLUMN_QUALIFIER).getString();
        double score = register(raster, map.get("raster").getFloatArray());
        scores.add(new SegmentScoreElement(id, score));
    }
    scores.sort(ScoreElement.SCORE_COMPARATOR.reversed());
    if (scores.size() > limit) {
        return scores.subList(0, limit);
    } else {
        return scores;
    }
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) ArrayList(java.util.ArrayList) Map(java.util.Map) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 20 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class HPCPShingle method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare helper data-structures. */
    final HashMap<String, DistanceElement> map = new HashMap<>();
    for (DistanceElement hit : partialResults) {
        if (hit.getDistance() <= this.distanceThreshold) {
            map.merge(hit.getId(), hit, (o, n) -> new SegmentDistanceElement(o.getId(), (o.getDistance() + n.getDistance()) / 2));
        }
    }
    /* Prepare final result-set. */
    final CorrespondenceFunction fkt = qc.getCorrespondenceFunction().orElse(this.correspondence);
    return ScoreElement.filterMaximumScores(map.entrySet().stream().map(e -> e.getValue().toScore(fkt)));
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) FFTUtil(org.vitrivr.cineast.core.util.dsp.fft.FFTUtil) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) Pair(org.vitrivr.cineast.core.data.Pair) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) HashMap(java.util.HashMap) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Aggregations

ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)28 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)17 ArrayList (java.util.ArrayList)16 SegmentDistanceElement (org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)11 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)8 List (java.util.List)7 ScoreElement (org.vitrivr.cineast.core.data.score.ScoreElement)7 HashMap (java.util.HashMap)6 DistanceElement (org.vitrivr.cineast.core.data.distance.DistanceElement)5 FloatVectorImpl (org.vitrivr.cineast.core.data.FloatVectorImpl)4 SegmentContainer (org.vitrivr.cineast.core.data.segments.SegmentContainer)4 StagedFeatureModule (org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule)4 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Pair (org.vitrivr.cineast.core.data.Pair)3 HPCP (org.vitrivr.cineast.core.util.audio.HPCP)3 FFTUtil (org.vitrivr.cineast.core.util.dsp.fft.FFTUtil)3 STFT (org.vitrivr.cineast.core.util.dsp.fft.STFT)3 HanningWindow (org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow)3 MathHelper (org.vitrivr.cineast.core.util.math.MathHelper)3