Package: nanonets
The NanoNets API Python WrapperNanonets provides an easy to use API to communicate with it's servers and build machine learning models and make predictions on image data.
The models that can be built are -Image ClassificationMulti-label ClassificationObject DetectionOCRCheck us out athttps://nanonets.com.To find out about our GUI solution or to get your API key, check outhttps://app.nanonets.comInstallationPip install -Run the following command from your terminal -pipinstallnanonetsSetuptools -To install using setuptools, run the following commands from your terminalgitclonehttps://github.com/NanoNets/nanonets-python-wrapper.gitcdnanonets-python-wrapper
pythonsetup.pyinstall--userCreate Models -To create a new modelHead over tohttps://app.nanonets.com, login, click on the 'API Keys' tab on the left.Click on 'COPY KEY'Create a model using the following python codefromnanonetsimportImageClassification# from nanonets import MultilabelClassification# from nanonets import ObjectDetection# from nanonets import OCRapi_key='YOUR_API_KEY_GOES_HERE'categories=['list','of','your','labels']model=ImageClassification(api_key,categories)This will print a Model ID that you should note down for future reference. You can also find this out by visitinghttps://app.nanonets.comPreparing training dataThe training data, needs to be put into a dictionary format wherefor image classification models -keys (str) - filepaths/urls of imagesvalues (str) - labels for each imagefor multilabel classification models -keys (str) - filepaths/urls of imagesvalues (List[str]) - list of labels for each imagefor object detection models -keys (str) - filepaths of imagesvalues (str) - annotation paths for each image (XML or JSON)for OCR models -keys (str) - filepaths of imagesvalues (str) - annotation paths for each image (XML or JSON)you can look into the data/annotations directory to get a better idea.Training and model statusTo train a model on some training data -model.train(training_dict,data_path_type='files')The images will get uploaded and the training will get initialised after.You can check if the model is trained or not at anytime by running the following command from a python console -api_key='YOUR_API_KEY_GOES_HERE'categories=['list','of','your','labels']model_id='YOUR_MODEL_ID'model=ImageClassification(api_key,categories,model_id=model_id)model._check_model_state()Or you can wait for Nanonets to email you once the training is finished.InferenceYou can run inference on a single image or multiple images. You can use urls as well as local files.api_key='YOUR_API_KEY_GOES_HERE'categories=['list','of','your','labels']model_id='YOUR_MODEL_ID'model=ImageClassification(api_key,categories,model_id=model_id)## list of file paths of several test imagesimg_dir='PATH_TO_YOUR_IMAGES_DIR'imglist=os.listdir(img_dir)imglist=[img_dir+'/'+xforxinimglist]## list of urls of several test imagesurls=['LIST','OF','YOUR','IMAGE','URLS']## prediction functions for single fileresp_one_file=model.predict_for_file(imglist[0])print("IC response - single image: ",resp_one_file)## prediction functions for multiple filesresp_mul_files=model.predict_for_files(imglist)print("IC response - multiple images: ",resp_mul_files)## prediction functions for single urlresp_one_url=model.predict_for_url(urls[0])print("IC response - single URL: ",resp_one_url)## prediction functions for multiple urlsresp_mul_urls=model.predict_for_urls(urls)print("IC response - multiple URLs: ",resp_mul_urls)NOTE: The data in thedatadirectory is meant to serve as examples and is generated randomly to demonstrate training and inference code in theexamplesdirectory. Use said data to understand the format requirements for the library and not for building models.