Let's say you have some images and would like to upload them to LandingLens. Instead of uploading from the LandingLens user interface (UI), you could upload the images directly with a script. In this case, you should understand the following two methods of the LandingLens SDK:
res=llens.media.upload(path, validate_extensions=True) ''' Upload media to platform.
Parameters ----------
path: str Path to the local file. split: str Set this media to one split ('train'/'dev'/'test'), '' represents Unassigned and is the default classification_name: str Set the media's classification if the project type is Classification or Anomaly Detection object_detection_xml: str Path to the Pascal VOC xml file for object detection project seg_mask: str Path to the segmentation mask file for segmentation project seg_defect_map: str Path to the segmentation defect_map.json file for segmentation project nothing_to_label: bool Set the media's label as OK, valid for object detection and segmetation project project_id: str Project id for which to fetch the media. Defaults to None - in this case, ll ens will read project id from the config file. validate_extensions: bool Defaults to True. Files other than jpg/jpeg/png/bmp will be skipped. If set to False, will try to upload all files. Behavior of platform for unexpected extensions may not be correct
Returns ------- dict{ "error_count": int # failed file count "files_with_errors": dict # failed filename and its error message "medias": list[dict[str, any]] Lists of media information "num_uploaded": int The number of uploaded media } '''
Parameters ---------- offset: int Defaults to 0. As in standard pagination. limit: int Max 1000. Defaults to 1000. As in standard pagination. no_pagination: bool If set to true, llens will fetch all media for a project given the filters. Limit and offset parameters will be ignored. Defaults to False. **metadata: Kwargs used as metadata that will be used for server side filtering of the results.
Returns ------- dict{ "medias": list[dict[str, any]] Lists of media information "num_requested": int limit - offset "count": int The number of media, len(media) "offset": int The number of offset when executing the method llens.media.ls() "limit": int The number of limit when executing the method llens.media.ls() } '''
The server refers to the MD5 checksum to prevent duplicate uploads. If a duplicate is detected, the server will display a 409 )Conflict) error.
Folder upload only supports raw images. It does not support labels.
Split
split can be directly assigned when uploading. Pass in the split name "train", "dev", or "test".
If no split or split = "", then the split will be unassigned.
Classification
Pass in the defect name to classification_name parameter, this class will be created if it does not exist.
# defect named defect-1, split is 'dev' llens.media.upload("./upload_test/classification/defect-1.bmp", classification_name="defect-1", split="dev", project_id=1839885)
# defect named defect-2, split is 'test' llens.media.upload("./upload_test/classification/defect-2.jpg", classification_name="defect-2", split="test", project_id=1839885)
Anomaly Detection
This process is similar to Classification. Pass to classification_name and indicate whether the images are normal or abnormal.
# normal, no split means 'unassigned' llens.media.upload("./upload_test/anomaly detection/normal.jpg", classification_name="normal", project_id=1839886)
# Instantiate the llens client llens = LandingLens()
# Fetch all media resp_ls=llens.media.ls(no_pagination=True)['medias']
# Iterate the media block by block for media in media: media_id = media['id'] media_name = media['name']
# Add the metadata 'defect_type' according to the media_name res = llens.metadata.upload( media_id, defect_type=int(media_name.split('.')[0][5:]) )
# Show the updated defect_type print(res['metadata']['defect_type']) # The output would be the number in the file name, i.e. # if the media name is 'image1.png', the printing output will be 1
Was this article helpful?
Thank you for your feedback! Our team will get back to you