Search in sources :

Example 16 with QueryConfig

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

the class InceptionResnetV2 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 QueryConfig

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

the class InceptionResnetV2 method getSimilar.

@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
    float[] encodingArray = null;
    if (!sc.getVideoFrames().isEmpty() && sc.getVideoFrames().get(0) != VideoFrame.EMPTY_VIDEO_FRAME) {
        // Case: segment contains video frames
        List<MultiImage> frames = sc.getVideoFrames().stream().map(VideoFrame::getImage).collect(Collectors.toList());
        encodingArray = encodeVideo(frames);
    } else if (sc.getMostRepresentativeFrame() != VideoFrame.EMPTY_VIDEO_FRAME) {
        // Case: segment contains image
        BufferedImage image = sc.getMostRepresentativeFrame().getImage().getBufferedImage();
        if (image != null) {
            encodingArray = encodeImage(image);
        } else {
            LOGGER.error("Could not get similar because image could not be converted to BufferedImage.");
        }
    }
    if (encodingArray == null) {
        LOGGER.error("Could not get similar because no acceptable modality was provided.");
        return new ArrayList<>();
    }
    // Ensure the correct distance function is used
    QueryConfig queryConfig = QueryConfig.clone(qc);
    queryConfig.setDistance(DISTANCE);
    return getSimilar(encodingArray, queryConfig);
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) MultiImage(org.vitrivr.cineast.core.data.raw.images.MultiImage) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage)

Example 18 with QueryConfig

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

the class StagedFeatureModule method getSimilar.

/**
 * This method executes a similarity query based on an existing segment. The query is executed in three stages (hence the name of the class):
 *
 * <ol>
 *     <li>Lookup: Retrieving the features associated with the provided segment ID.</li>
 *     <li>Similarity search: Performing the similarity query in the underlying storage engine.</li>
 *     <li>Post-processing: Aggregating the query results into the final Score elements.</li>
 * </ol>
 * <p>
 * Even though it is possible to re-implement this method, it is not recommended. Instead, try to override
 * the methods that represent the different stages.
 *
 * @param segmentId ID of the segment that is used as example.
 * @param qc        QueryConfiguration
 * @return List of results
 */
@Override
public List<ScoreElement> getSimilar(String segmentId, ReadableQueryConfig qc) {
    /* Load default query-config. */
    QueryConfig qcc = this.defaultQueryConfig(qc);
    /* Lookup features. */
    List<float[]> features = this.selector.getFeatureVectors(GENERIC_ID_COLUMN_QUALIFIER, new StringTypeProvider(segmentId), FEATURE_COLUMN_QUALIFIER);
    if (features.isEmpty()) {
        LOGGER.warn("No features could be fetched for the provided segmentId '{}'. Aborting query execution...", segmentId);
        return new ArrayList<>(0);
    }
    /* Generate a list of QueryConfigs for the feature. */
    List<ReadableQueryConfig> configs = this.generateQueryConfigsForFeatures(qcc, features);
    /* Start query lookup phase. */
    List<SegmentDistanceElement> partialResults = this.lookup(features, configs);
    /* Start query-results post-processing phase. */
    return this.postprocessQuery(partialResults, qcc);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 19 with QueryConfig

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

the class StagedFeatureModule method getSimilar.

/**
 * This method executes a regular similarity query based on a provided SegmentContainer. The query is executed in three stages (hence the name of the class):
 *
 * <ol>
 *     <li>Pre-processing: Extracting features from the SegmentContainer.</li>
 *     <li>Similarity search: Performing the similarity query in the underlying storage engine.</li>
 *     <li>Post-processing: Aggregating the query results into the final Score elements.</li>
 * </ol>
 * <p>
 * Even though it is possible to re-implement this method, it is not recommended. Instead, try to override
 * the methods that represent the different stages.
 *
 * @param sc SegmentContainer to base the query on.
 * @param qc QueryConfiguration
 * @return List of results
 */
@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
    /* Load default query-config. */
    QueryConfig qcc = this.defaultQueryConfig(qc);
    /* Extract features. */
    List<float[]> features = this.preprocessQuery(sc, qcc);
    if (features == null || features.isEmpty()) {
        LOGGER.warn("No features could be generated from the provided query. Aborting query execution...");
        return new ArrayList<>(0);
    }
    /* Generates a list of QueryConfigs for the feature. */
    List<ReadableQueryConfig> configs = this.generateQueryConfigsForFeatures(qcc, features);
    /* Start query lookup phase. */
    List<SegmentDistanceElement> partialResults = this.lookup(features, configs);
    return this.postprocessQuery(partialResults, qcc);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Aggregations

QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)19 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)15 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 SegmentDistanceElement (org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)3 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)2 SemanticMap (org.vitrivr.cineast.core.data.SemanticMap)2 StringDoublePair (org.vitrivr.cineast.core.data.StringDoublePair)2 MediaObjectMetadataDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectMetadataDescriptor)2 DeepLabLabel (org.vitrivr.cineast.core.features.neuralnet.tf.models.deeplab.DeepLabLabel)2 ContinuousRetrievalLogic (org.vitrivr.cineast.standalone.util.ContinuousRetrievalLogic)2