# alfred **Repository Path**: zzb32/alfred ## Basic Information - **Project Name**: alfred - **Description**: alfred-py: A deep learning utility library for visualization and sensor fusion purpose - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-27 - **Last Updated**: 2024-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Alfred *Alfred* is command line tool for deep-learning usage. if you want split an video into image frames or combine frames into a single video, then **alfred** is what you want. ## Install To install **alfred**, it is very simple: ```shell sudo pip3 install alfred-py ``` **alfred is both a lib and a tool, you can import it's APIs, or you can directly call it inside your terminal**. A glance of alfred, after you installed above package, you will have `alfred`: - **`data`** module: ```shell # show VOC annotations alfred data vocview -i JPEGImages/ -l Annotations/ # show coco anntations alfred data cocoview -j annotations/instance_2017.json -i images/ # show yolo annotations alfred data yoloview -i images -l labels # show detection label with txt format alfred data txtview -i images/ -l txts/ # show more of data alfred data -h # eval tools alfred data evalvoc -h ``` - **`cab`** module: ```shell # count files number of a type alfred cab count -d ./images -t jpg # split a txt file into train and test alfred cab split -f all.txt -r 0.9,0.1 -n train,val ``` - **`vision`** module; ```shell # extract video to images alfred vision extract -v video.mp4 # combine images to video alfred vision 2video -d images/ ``` - **`-h`** to see more: ```shell usage: alfred [-h] [--version] {vision,text,scrap,cab,data} ... positional arguments: {vision,text,scrap,cab,data} vision vision related commands. text text related commands. scrap scrap related commands. cab cabinet related commands. data data related commands. optional arguments: -h, --help show this help message and exit --version, -v show version info. ``` **inside every child module, you can call it's `-h` as well: `alfred text -h`.** > if you are on windows, you can install pycocotools via: `pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"`, we have made pycocotools as an dependencies since we need pycoco API. ## Updates - 2050-: *to be continue*; - **2020.09.27**: Now, yolo and VOC can convert to each other, so that using Alfred you can: - convert yolo2voc; - convert voc2yolo; - convert voc2coco; - convert coco2voc; By this, you can convert any labeling format of each other. - 2020-09-08: After a long time past, **alfred** got some updates: We providing `coco2yolo` ability inside it. Users can run this command convert your data to yolo format: ``` alfred data coco2yolo -i images/ -j annotations/val_split_2020.json ``` Only should provided is your image root path and your json file. And then all result will generated into `yolo` folder under images or in images parent dir. After that (you got your yolo folder), then you can visualize the conversion result to see if it correct or not: ``` alfred data yolovview -i images/ -l labels/ ```  - 2020-07-27: After a long time past, **alfred** finally get some updates:  Now, you can using alfred draw Chinese charactors on image without xxxx undefined encodes. ```python from alfred.utils.cv_wrapper import put_cn_txt_on_img img = put_cn_txt_on_img(img, spt[-1], [points[0][0], points[0][1]-25], 1.0, (255, 255, 255)) ``` Also, you now can **merge** 2 VOC datasets! This is helpful when you have 2 dataset and you want merge them into a single one. ``` alfred data mergevoc -h ``` You can see more promotes. - 2020-03-08:Several new files added in **alfred**: ``` alfred.utils.file_io: Provide file io utils for common purpose alfred.dl.torch.env: Provide seed or env setup in pytorch (same API as detectron2) alfred.dl.torch.distribute: utils used for distribute training when using pytorch ``` - 2020-03-04: We have added some **evaluation tool** to calculate mAP for object detection model performance evaluation, it's useful and can visualize result:   this usage is also quite simple: ``` alfred data evalvoc -g ground-truth -d detection-results -im images ``` where `-g` is your ground truth dir (contains xmls or txts), `-d` is your detection result files dir, `-im` is your images fodler. You only need save all your detected results into txts, one image one txt, and format like this: ```shell bottle 0.14981 80 1 295 500 bus 0.12601 36 13 404 316 horse 0.12526 430 117 500 307 pottedplant 0.14585 212 78 292 118 tvmonitor 0.070565 388 89 500 196 ``` - 2020-02-27: We just update a `license` module inside alfred, say you want apply license to your project or update license, simple: ```shell script alfred cab license -o 'MANA' -n 'YoloV3' -u 'manaai.cn' ``` you can found more detail usage with `alfred cab license -h` - 2020-02-11: open3d has changed their API. we have updated new open3d inside alfred, you can simply using latest open3d and run `python3 examples/draw_3d_pointcloud.py` you will see this:  - 2020-02-10: **alfred** now support windows (experimental); - 2020-02-01: **武汉加油**! *alfred* fix windows pip install problem related to encoding 'gbk'; - 2020-01-14: Added cabinet module, also add some utils under data module; - 2019-07-18: 1000 classes imagenet labelmap added. Call it from: ```python from alfred.vis.image.get_dataset_label_map import imagenet_labelmap # also, coco, voc, cityscapes labelmap were all added in from alfred.vis.image.get_dataset_label_map import coco_labelmap from alfred.vis.image.get_dataset_label_map import voc_labelmap from alfred.vis.image.get_dataset_label_map import cityscapes_labelmap ``` - 2019-07-13: We add a VOC check module in command line usage, you can now visualize your VOC format detection data like this: ``` alfred data voc_view -i ./images -l labels/ ``` - 2019-05-17: We adding **open3d** as a lib to visual 3d point cloud in python. Now you can do some simple preparation and visual 3d box right on lidar points and show like opencv!!  You can achieve this by only using **alfred-py** and **open3d**! example code can be seen under `examples/draw_3d_pointcloud.py`. **code updated with latest open3d API**!. - 2019-05-10: A minor updates but **really useful** which we called **mute_tf**, do you want to disable tensorflow ignoring log? simply do this!! ```python from alfred.dl.tf.common import mute_tf mute_tf() import tensorflow as tf ``` Then, the logging message were gone.... - 2019-05-07: Adding some protos, now you can parsing tensorflow coco labelmap by using alfred: ```python from alfred.protos.labelmap_pb2 import LabelMap from google.protobuf import text_format with open('coco.prototxt', 'r') as f: lm = LabelMap() lm = text_format.Merge(str(f.read()), lm) names_list = [i.display_name for i in lm.item] print(names_list) ``` - 2019-04-25: Adding KITTI fusion, now you can get projection from 3D label to image like this: we will also add more fusion utils such as for *nuScene* dataset. We providing kitti fusion kitti for convert `camera link 3d points` to image pixel, and convert `lidar link 3d points` to image pixel. Roughly going through of APIs like this: ```python # convert lidar prediction to image pixel from alfred.fusion.kitti_fusion import LidarCamCalibData, \ load_pc_from_file, lidar_pts_to_cam0_frame, lidar_pt_to_cam0_frame from alfred.fusion.common import draw_3d_box, compute_3d_box_lidar_coords # consit of prediction of lidar # which is x,y,z,h,w,l,rotation_y res = [[4.481686, 5.147319, -1.0229858, 1.5728549, 3.646751, 1.5121397, 1.5486346], [-2.5172017, 5.0262384, -1.0679419, 1.6241353, 4.0445814, 1.4938312, 1.620804], [1.1783253, -2.9209857, -0.9852259, 1.5852798, 3.7360613, 1.4671413, 1.5811548]] for p in res: xyz = np.array([p[: 3]]) c2d = lidar_pt_to_cam0_frame(xyz, frame_calib) if c2d is not None: cv2.circle(img, (int(c2d[0]), int(c2d[1])), 3, (0, 255, 255), -1) hwl = np.array([p[3: 6]]) r_y = [p[6]] pts3d = compute_3d_box_lidar_coords(xyz, hwl, angles=r_y, origin=(0.5, 0.5, 0.5), axis=2) pts2d = [] for pt in pts3d[0]: coords = lidar_pt_to_cam0_frame(pt, frame_calib) if coords is not None: pts2d.append(coords[:2]) pts2d = np.array(pts2d) draw_3d_box(pts2d, img) ``` And you can see something like this: **note**: `compute_3d_box_lidar_coords` for lidar prediction, `compute_3d_box_cam_coords` for KITTI label, **cause KITTI label is based on camera coordinates!**.
