API JSON Limits 100 features

In some cases, 51% only of the Image Segmentation elements were recognized, leaving substantial portions out. For example, in this image (b8lnX0wIbI0Sn58c9Qk9ba), the Road element was neglected, accounting for 25 % of the whole photo. Strangely, asking only the Road feature gave the correct result. I suppose the reason is that the system computes 100 features per request, even with pagination. This number sometimes included a minor bit of images, which brings the count to 100, before completing all the features. Using a simple python algorithm I got only 100 feature. Why?

Maybe you show some code to understand the problem?

It is possible to change page size with per_page parameter (defaults to 100).
My guess is that your code does not follow pagination links correctly. If per_page=10 only gives you 10 results total, this is most likely the case.

the code can be retrieved from Github:
import requests
def download() dict:
payload = {client_id:___________,image_keys:b8lnX0wIbI0Sn58c9Qk9ba}
r = requests.get(https://a.mapillary.com/v3/object_detections/segmentations,params=payload)
a = r.json()
return a

Thanks, just tried pagination, but it didn’t work. Still 100 features

Seems like this specific image has exactly 100 segmentations. However, when you change the line to this:
payload = {‘client_id’:‘xxx’,‘image_keys’:‘b8lnX0wIbI0Sn58c9Qk9ba’,‘per_page’:‘10’}
you will get 10 results and in the headers (accessible through r.links()) there is a link for the next page with corresponding next_page_token value.

EDIT: If you want to test getting more segmentations then you can put more image keys in the image_keys (comma separated) or use the bbox parameter.

Thanks for the elegant header solution, but it seems it doesn’t work with this case.

"Seems like this specific image has exactly 100 segmentations" : it happens with several images. When you have more than 100 features it cuts all the features above 100. Specifically, in the b8lnX0wIbI0Sn58c9Qk9ba if you request construction* features only (which are not present in the 100 limits) it gets out the road as follows:
construction–flat–road area 0.7051044040256077 %
construction–flat–road area 25.044992234971787 %
construction–flat–sidewalk area 3.94492679172092 %
construction–barrier–curb area 0.5103853013780382 %

Moreover, if you ask for:
payload = {‘client_id’:’____________________’,‘image_keys’:p,‘values’:e,‘per_page’:‘101’}
it gives you back 100 features only, so pagination seems not to be the main issue.

I modified your code and gave it a random bunch of image keys like this:

import requests
def download() -> dict:
    payload = {'client_id':'CLIENT_ID','image_keys':'Zc0l4OMNEBtxARWTeRej8m,bAjgAg51zFPbDGvZXNYlFr,EkQ3O4johNviwkB7oo2fE5,sgeSCXwITHTDx5MfoNjf4n,5sun8dOtUklFzFWyDl8x5I,naVGnkrNcQ8kydgWlaYWhz,3A6ps4C6yaN4LvJAheZUZP,oC5Pr6z7iGsssthZE372P6,wXD6E8q1bw3RRSg5fANXF1,skCMMRzKI9HHBBcrqX2252,UThF6VXUTEg1UtgiJsIfn4,P6ITH6kqGZ4mQrV1cC48Is,NO0a9hzW3Wd8l6OUEwxmcw,gCCuF0mVup31WoJ7Jn4XGZ,e5BJWo5EPZkpASLtM8aAFl,E8aNKN0UFdRtZmOsgxizj9,YDuvptgQg1RxYraQmdNBKz,VFpI1Rk8VzSCKSZyzySKGo,vg9LDYx94g8u8d8QJbq0PK,sYWWAHRCVJggfwF8qYmD1c,sy0jyhGZBQ1O4Qoi1fPxc5,JFwkAbIOxVbVCawdvdzdGy,D2x532gfcyJM3EqnhCQW79,CrUS8ILL8avn51skzaFF8l,d00q8whLsbpjxQC9UvqI0R,HTVbfvUptaHXfOnYxNYKTr,s8sga6C7yaHInLKAIcMkbA,XbalsBtBSoTZsL7hQI7s4E,sIrD0t1U1ryAUFbKnSGXQh,4Ji00oMZOoLmGns0EV6PlR,K1upwFCPpnGfKBucpWsMgu,aQ7cXyofQyRc9DxXjjHPG1,Jotr35EGT29QTFxwE8c4Mw,u5JrXoyBFbgk82CZqk7OCt,hZr7EKeE2gYRZaV60cWC22','per_page':'101'}
    r = requests.get("https://a.mapillary.com/v3/object_detections/segmentations",params=payload)
    a = r.json()
    if 'next' in r.links:
        print (r.links['next'])
    return a

Like this the code prints out the url for next page and number of features is 101. But using your image key it shows exactly 100 and no next url. Curiouser and curiouser as they say.

Looked at that specific image again. There are following segmentations present:

Segmentation Count
construction–barrier–curb 23
construction–barrier–fence 8
construction–barrier–guard-rail 2
construction–barrier–wall 13
construction–flat–bike-lane 1
construction–flat–parking 1
construction–flat–road 3
construction–flat–sidewalk 3
construction–structure–building 5
human–person 3
human–rider–motorcyclist 1
marking–continuous–dashed 1
nature–sand 2
nature–sky 1
nature–snow 2
nature–terrain 14
nature–water 1
nature–vegetation 19
object–support–pole 8
object–traffic-light–pedestrians 1
object–vehicle–car 1
Total 113

So it seems that there is a limit on segmentations per image shown, but not per query. Suitable workaround would be querying the data not by images but by segmentation values. That way number of segmentations per image stays lower. There will be some segmentations missing in certain cases, i.e. over 100 people on single image, but larger features like road and sky should be always present.

I was thinking to ask each time for a different feature family, as nature*, construction*, so that for each query result will be under 100, then pack it all the features together. Is it what have you done? Can you share algorithm which brought you to the shown results? I am the coordinator of a research group in Architectural Engineering, so that coding is not exactly my field of study, but I love it ! Thanks again for your help!

Code is here: random-mapillary-stuff/segmentation-downloader.py at master · taneljairus/random-mapillary-stuff · GitHub

It takes bounding box as input (could be altered to get specific images, sequences, users and so on), gets image keys and then loops them through all possible segmentation values. The result is saved as JSON file.