You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A collection of commonly used tools for general Computer Vision or other Deep Learning projects.
Installation
pip install cvbox
File search and filtering utilities
Utilities to scan files and folders, with options to filter by extension, folders to ignore, etc. Works on both Windows and Linux
fromcvbox.searchimportlistfiles, listfiles_gendir_to_list="/path/to/folder/to/search"# Store all found files in an arrayfiles=listfiles(dir_to_list)
print(files) # Show all the filtered files in dir_to_list# Only include .jpg, .png and .jpeg filesimage_paths=listfiles(dir_to_list, extensions=(".jpg",".png","jpeg"))
print(image_paths)
# Return as string instead of pathlib objectimage_paths=listfiles(dir_to_list, extensions=(".jpg",".png","jpeg"),return_as_pathlib=False)
print(image_paths)
# Return filenames onlyimage_names=listfiles(dir_to_list, extensions=(".jpg",".png","jpeg"),return_filename_only=True)
print(image_names)
# Exclude certain extensions (Should not be used together with extensions= argument)# List all files in dir_to_list that are not .txt or .doc files.files_exclude_txt=listfiles(dir_to_list,extensions_exclude=(".txt",".doc"))
# Use generator and process each file lazily. This works on very large folders with # large number (>500k) of files# Just replace listfiles with listfiles_gen (Same function signature as listfiles)forfinlistfiles_gen(dir_to_list):
# Operate on files lazilyprint(f)
File IO functions - Exporting object state to/from files
Exporting python objects to pickle binary files
fromcvbox.fileioimportsave_pkl, load_pkl### Quickly serialize/export python objects (can be arrays, dicts, etc) into### files that can be re-used again (object must be pickle-able)arr= [1,2,3,4,5]
save_pkl(arr, "arr_output.pkl") # Generates arr_output.pkl in the current directoryarr_loaded=load_pkl("arr_output.pkl") # Restore the array object from fileprint(arr_loaded) # [1, 2, 3, 4, 5]
Exporting dictionary objects into JSON text files
fromcvbox.fileioimportsave_json, load_jsondic= [ {"category":"Car","movement": lambda : "Drive" },
{"category":"Plane","movement": lambda : "Fly" }]
save_json("json_output.txt", dic) # Dictionary object is serialized into txt# Load dictionary from json formatted textdic_loaded=load_json("json_output.txt")
print(dic_loaded)
# [{'category': 'Car', 'movement': '<not serializable>'},# {'category': 'Plane', 'movement': '<not serializable>'}]# Note that non-pickle-able objects such as lambda functions are converted into <not serializable> by default