Package: bp-storage
BrainPlug Storage LibraryLibrary to load, augment and different dataset formats for use in machine learning models.Note: The repo is still work in progress, so documentation might not be up to dateGetting StartedStorage Library allows loading and augmentation in various data formats. It even allows to generateTensorflowTf-Records and load them (coming soon (TM)).pip3installbp-storage# or install locally from sourcepip3install.Currently the library has 4 parts:storage.classification- Allows to load simple classification datasetsstorage.kitti- Allows to load the kitti format for usage in detectors (3D Data not supported currently)storage.beard- Allows to load beard format (format optimized for localization tasks)storage.utils- Various helper functionsIn general each data loader will create a python generator that can be used to loop over the data. Datasets in general are split into different types (defined instorage.utils.DataType):TRAINING- Used for general training purposesDEVELOPMENT- Used for validation and exploration during the development process (you will probably make certain assumptions about the structure of the dataset through this data)VALIDATION- Final validation data used to measure the performance of the trained model and to validate your assumptionsThese datatypes are added to the end of the enum and the creation functions also allow you to filter the dataset for certain types.ExamplesGeneral ConceptsEach load function allows to resize the images through 3 parameters, which contain enums:resize[storage.utils.ResizeMode] - Defines how the images are resized and if it should be paddedpad_mode[storage.utils.PadMode] - In case of padding defines if the image should be pinned to top left corner or centeredpad_color[Color Array] - Defines the color of the padding, ifResizeMode.PAD_COLORis selectedEach load function also allows to specify the maximum size of the output image throughsizeand if the dataset type (i.e.storage.utils.DataType) is provided for each element in the generator throughshow_btype. It also allows to filter only for a specific btype through theonlyargument, which expects a single or a list of multipleDataType.ClassificationThis is the simples type of dataset:importstoragefromstorage.utilsimportResizeMode,DataType# DEBUG: using cv2 for debug outputimportcv2# load the generatorclasses,gen=storage.classification.load(folder,size=(512,512),resize=ResizeMode.FIT,only=DataType.TRAINING,show_btype=True)print("Found classes:{}".format(classes))# DEBUG: show the output of the generatorforimg,label,dsingen:cv2.putText(img,label,(10,10),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,0),2)# show the resultcv2.imshow("Storage Output",img)cv2.waitKey(0)Kitti & BeardThe loading of kitti and beard data is quite similar (i.e. kitti uses the beard loader internally). Both function should have similar signatures. The only difference are:beard_styleparameter forkitti.load(), which switches between classic kitti format and beard generator style output.classesparameter forkitti.load(), which allows to provide classes that deviate from default kitti classes (for beard, these are stored in the config file)Therefore we will only look at beard loading here:importstoragefromstorage.utilsimportResizeMode,PadMode,DataType# DEBUG: using cv2 for debug outputimportcv2# load the generatorconfig,gen=storage.beard.load(folder,only=DataType.DEVELOPMENT,size=(512,512),resize=ResizeMode.PAD_COLOR,pad_color=(255,255,255),pad_mode=PadMode,show_btype=False)# DEBUG: show the output of the generatorcolors=storage.utils.get_spaced_colors(len(classes)+1)[1:]forimg,gdata,mdataingen:# note: gdata contains global image information (empty in kitti) and mdata hold classes and locations of objects# go through all elementsforiteminmdata:# highlight bbsifstorage.utils.const.ITEM_BBOXinitem:# retrieve the boxescoords=item[storage.utils.const.ITEM_BBOX]cls=item[storage.utils.const.ITEM_CLASS]# draw the bounding boxcv2.rectangle(img,(coords[0],coords[1]),(coords[2],coords[3]),colors[cls],2)cv2.putText(img,cls,(coords[0],coords[3]+10),cv2.FONT_HERSHEY_SIMPLEX,0.4,colors[cls],1,cv2.LINE_AA)# show the resultcv2.imshow("Storage Output",img)cv2.waitKey(0)For additional insights take a look at thescriptsfolder.NOTE:In the default case the class attribute stored initemfor kitti data is namedtypeand notclass(as stored instorage.utils.const.ITEM_CLASS)Dataset structuresBeardandKittistructures are described in separate documents. Classification expects a simple structure. Like in beard data is split into multiple folders for the datatype (train,val,dev). Each folder contains a subfolder for each class that should be classified (e.g.catanddog). These subfolders then contain the actual images.Dependencieslyconorcv2- for fast loading of images and resizing (pip install lycon, however there seems not to be real windows support at the moment) [NOTE: you can also use cv2 instead, the library will adapt automatically]default python stack (numpy,pandas, etc.)PerformanceOne of the performance bottlenecks appears to be the numpypadfunctions. However they are currently rewritten (seehere) and might improve performance in future versions of numpy.Known IssuesAugmentation only works with absolute coordinates on x-y ordering! (otherwise might produce wrong results, usetest_inputto verify!)LicensePublished under MIT License.