Retrieval of multiple images

30 views
Skip to first unread message

Jason

unread,
Mar 9, 2021, 4:13:03 AM3/9/21
to lire-dev
Hi all,
I was wondering if LireSolr could manage the retrieval of multiple images, so for istance, an Id query, where the Ids are more than one, and thus aggregate the final results. (obviously the question is for all types of queries)
Looking at the code, if I'm not mistaken, this is not possible...

So the question is fairly simple: Am I wrong or right? If I'm wrong, any tips on how to handle a "multiple search"?

B.S.

Mathias Lux

unread,
Mar 9, 2021, 5:49:01 AM3/9/21
to lire...@googlegroups.com
Hi!

The aggregation is the problem. As there are so many ways to do this (e.g. averaging the query vector, averaging the distance, using inverted ranks, ..) and none of them is applicable to all possible use cases, we didn't put in an automated way to do that. My bet would be: Run multiple queries and use inverted or averaged rank to rank the final result.

cheers,
Mathias

--
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "lire-dev" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an lire-dev+u...@googlegroups.com.
Wenn Sie diese Diskussion im Web verfolgen möchten, rufen Sie https://groups.google.com/d/msgid/lire-dev/38f94c84-72c3-42a0-a6b7-b48f363b7d9bn%40googlegroups.com auf.


--
Priv.-Doz. Dr. Dipl.-Ing. Mathias Lux
Associate Professor at Klagenfurt University, Austria
http://tinyurl.com/mlux-itec ... contact and cv

LIRE image search engine - http://www.lire-project.net

Jason

unread,
Mar 9, 2021, 5:57:03 AM3/9/21
to lire-dev
Hi,
thanks for the reply.
I'll try something, and if I found any reasonable solution I will post it!

B.R.

Jason

unread,
Mar 10, 2021, 4:41:58 AM3/10/21
to lire-dev
Hi again, 
I found a possible solution using like query vector the average of every image's feature vector.
What do you think about it?

private void handleMultipleIdSearch_IDlike(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, InstantiationException, IllegalAccessException {
SolrIndexSearcher searcher = req.getSearcher();
String[] r = req.getParams().get("M_id").split("&");
double[] vector = new double["your_dimension"];
double[] tmp = new double[
"your_dimension"  ];
Query query = null;

String tmpParamField = req.getParams().get("field", "cl_ha");
if (!tmpParamField.endsWith("_ha"))
tmpParamField += "_ha";

final String paramField = tmpParamField;
GlobalFeature queryFeature = (GlobalFeature) FeatureRegistry.getClassForHashField(paramField).newInstance();
numberOfQueryTerms = req.getParams().getDouble("accuracy", DEFAULT_NUMBER_OF_QUERY_TERMS);
numberOfCandidateResults = req.getParams().getInt("candidates", DEFAULT_NUMBER_OF_CANDIDATES);
useMetricSpaces = req.getParams().getBool("ms", DEFAULT_USE_METRIC_SPACES);
int paramRows = req.getParams().getInt("rows", defaultNumberOfResults);
rsp.add("QueryField", paramField);
rsp.add("QueryFeature", queryFeature.getClass().getName());

for (String string : r) {
int queryDocId = searcher.getFirstMatch(new Term("id", string));
if (queryDocId > -1) {
BinaryDocValues binaryValues = new RandomAccessBinaryDocValues(() -> {
try {
return MultiDocValues.getBinaryValues(searcher.getIndexReader(), FeatureRegistry.getFeatureFieldName(paramField));
} catch (IOException e) {
throw new RuntimeException("BinaryDocValues problem.", e);
}
});
if (binaryValues == null)
rsp.add("Error", "Could not find the DocValues of the query document. Are they in the index? Id: " + string);
BytesRef bvBytesRef = getBytesRef(binaryValues, queryDocId);
queryFeature.setByteArrayRepresentation(bvBytesRef.bytes, bvBytesRef.offset, bvBytesRef.length);

tmp = queryFeature.getFeatureVector();
for (int i = 0; i < vector.length; i++)
vector[i] += tmp[i];

} else {
rsp.add("Error", "Did not find an image with the given id " + string);
}
}
for (int i = 0; i < vector.length; i++)
vector[i] /= (double)r.length;
rsp.add("vector", Arrays.toString(vector));

try {
if (!useMetricSpaces) {
HashTermStatistics.addToStatistics(searcher, paramField);
int[] hashes = BitSampling.generateHashes(vector);
query = createQuery(hashes, paramField, numberOfQueryTerms);
} else {
rsp.add("Error", "Feature not supported by MetricSpaces: " + queryFeature.getClass().getSimpleName());
}
doSearch(req, rsp, searcher, paramField, paramRows, getFilterQueries(req), query, queryFeature);
} catch (Exception e) {
rsp.add("Error", "There was an error with your search: " + e.getMessage());
}

}


Jason

unread,
Mar 12, 2021, 4:58:09 AM3/12/21
to lire-dev
Hi,
sorry to bother you again, but I need some help.
The code I posted, basically, takes all the images selected and for all of them takes the feature vector, and lastly I have an averaged vector to use for query.
But the problem I'm facing is a bit strange: when I launch my web-app and try the retrieval of multiple images, in theory I would expect the first results to be the same images selected (because they have equal distant from the mean vector), but in practice what I found is that the first image result is one of the images selected (with its distance equal to 0, and this is strange) and the remaining images are further down the resulting list...

Would you have any suggestions, based on the code i posted?

B.R.
Il giorno martedì 9 marzo 2021 alle 11:57:03 UTC+1 Jason ha scritto:
Reply all
Reply to author
Forward
0 new messages