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);
}
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);
}
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);
}
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);
}
Aggregations