From 9cecc5051ae3e768da08962d44cc7ad7c0d2e26a Mon Sep 17 00:00:00 2001 From: perseusdg <43143075+perseusdg@users.noreply.github.com> Date: Wed, 24 Nov 2021 03:39:57 +0530 Subject: [PATCH] -Modified Dockerfile.base to cudagl -Changed demo to take in input from demoConfig.yaml file -Readme changes for demo.md --- .gitignore | 1 + demo/demo/demo.cpp | 112 +++++++++++---------- demo/demoConfig.yaml | 22 +++++ docker/Dockerfile.base | 159 +++++++++++++++++++++++------- docker/README.md | 5 +- docker/assets/entrypoint_setup.sh | 123 +++++++++++++++++++++++ docker/assets/terminator_config | 18 ++++ docker/docker_launch.sh | 9 ++ docs/demo.md | 43 ++++---- include/tkDNN/utils.h | 17 +++- scripts/checkExecTimes.py | 37 +++++++ 11 files changed, 422 insertions(+), 124 deletions(-) create mode 100644 demo/demoConfig.yaml create mode 100755 docker/assets/entrypoint_setup.sh create mode 100644 docker/assets/terminator_config create mode 100755 docker/docker_launch.sh create mode 100644 scripts/checkExecTimes.py diff --git a/.gitignore b/.gitignore index 683834c..22f7f94 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ scripts/COCO_val2017/* scripts/COCO_val2017.zip scripts/all_labels.txt /cmake/cuda_script +/cmake-build-debug/ diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 967c996..b1cf574 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -18,64 +18,57 @@ void sig_handler(int signo) { int main(int argc, char *argv[]) { - std::cout<<"detection\n"; signal(SIGINT, sig_handler); +#ifdef __linux__ + std::string config_file = "../demo/demoConfig.yaml"; +#elif _WIN32 + std::string config_file = "..\\..\\..\\demo\\demoConfig.yaml"; +#endif - std::string net = "yolo4tiny_fp32.rt"; - #ifdef __linux__ - std::string cfgPath = "../tests/darknet/cfg/yolo4tiny.cfg"; - #elif _WIN32 - std::string cfgPath = "..\\tests\\darknet\\cfg\\yolo4tiny.cfg"; - #endif - - #ifdef __linux__ - std::string namePath = "../tests/darknet/names/coco.names"; - #elif _WIN32 - std::string namePath = "..\\tests\\darknet\\names\\coco.names"; - #endif - - if(argc > 1) - net = argv[1]; - #ifdef __linux__ - std::string input = "../demo/yolo_test.mp4"; - #elif _WIN32 - std::string input = "..\\demo\\yolo_test.mp4"; - #endif - - char ntype = 'y'; - if(argc > 2) - input = argv[2]; - if(argc > 3) - ntype = argv[3][0]; - int n_classes = 80; - if(argc > 4) - n_classes = atoi(argv[4]); - if(argc > 5) - cfgPath = argv[5]; - if(argc > 6) - namePath = argv[6]; - int n_batch = 1; - if(argc > 7) - n_batch = atoi(argv[7]); - bool show = true; - if(argc > 8) - show = atoi(argv[8]); - float conf_thresh=0.3; - if(argc >= 9) - conf_thresh = atof(argv[9]); - - if(n_batch < 1 || n_batch > 64) - FatalError("Batch dim not supported"); - - if(!show) - SAVE_RESULT = true; - - if(ntype == 'c' || ntype == 'm'){ - cfgPath = ""; - namePath = ""; - + if(argc > 1){ + config_file = argv[1]; } + + YAML::Node conf = YAMLloadConf(config_file); + if(!conf){ + FatalError("Problem with config file"); + } + + + std::string net = YAMLgetConf(conf,"net","yolo4tiny_fp32.rt"); + if(!fileExist(net.c_str())) { + FatalError("The given network does not exist. Create the rt first."); + } + +#ifdef __linux__ + std::string input = YAMLgetConf(conf, "input", "../demo/yolo_test.mp4"); + std::string cfgPath = YAMLgetConf(conf,"cfg_input", "../tests/darknet/cfg/yolo4tiny.cfg"); + std::string namePath = YAMLgetConf(conf,"name_input","../tests/darknet/names/coco.names"); +#elif _WIN32 + std::string input = YAMLgetConf(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4"); + std::string cfgPath = YAMLgetConf(conf,"cfg_win_input","..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg"); + std::string namePath = YAMLgetConf(conf,"name_win_input","..\\..\\..\\tests\\darknet\\names\\coco.names"); +#endif + if(!fileExist(input.c_str())) + FatalError("The given input video does not exist."); + + char ntype = YAMLgetConf(conf, "ntype", 'y'); + int n_classes = YAMLgetConf(conf, "n_classes", 80); + int n_batch = YAMLgetConf(conf, "n_batch", 1); + if(n_batch < 1 || n_batch > 64) + FatalError("Batch dim not supported"); + float conf_thresh = YAMLgetConf(conf, "conf_thresh", 0.3); + bool show = YAMLgetConf(conf, "show", true); + bool save = YAMLgetConf(conf, "save", false); + + + + + + + + tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; tk::dnn::MobilenetDetection mbnet; @@ -98,6 +91,11 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } + if(ntype == 'c' || ntype == 'm'){ + cfgPath = ""; + namePath = ""; + } + detNN->init(net,cfgPath,namePath,n_classes,n_batch,conf_thresh); gRun = true; @@ -109,7 +107,7 @@ int main(int argc, char *argv[]) { std::cout<<"camera started\n"; cv::VideoWriter resultVideo; - if(SAVE_RESULT) { + if(save) { int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h)); @@ -149,7 +147,7 @@ int main(int argc, char *argv[]) { cv::waitKey(1); } } - if(n_batch == 1 && SAVE_RESULT) + if(n_batch == 1 && save) resultVideo << frame; } @@ -157,7 +155,7 @@ int main(int argc, char *argv[]) { double mean = 0; std::cout<stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; + std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; for(int i=0; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); std::cout<<"Avg: "<> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/nvidia.conf + + +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/lib:/usr/lib/x86_64-linux-gnu:/usr/local/lib:${LD_LIBRARY_PATH} ENV NVIDIA_VISIBLE_DEVICES all -RUN echo "INSTALL OPENCV" -RUN apt-get install -y build-essential \ - unzip \ - pkg-config \ - libjpeg-dev \ - libpng-dev \ - libtiff-dev \ - libavcodec-dev \ - libavformat-dev \ - libswscale-dev \ - libv4l-dev \ - libxvidcore-dev \ - libx264-dev \ - libgtk-3-dev \ - libatlas-base-dev \ - gfortran-9 \ - libtbb-dev \ - libgstreamer1.0-dev \ - libgstreamer-plugins-base1.0-dev \ - libdc1394-22-dev \ - libavresample-dev -RUN cd && wget https://github.com/opencv/opencv/archive/4.5.4.tar.gz && tar -xf 4.5.4.tar.gz && rm *.tar.gz -RUN cd && wget https://github.com/opencv/opencv_contrib/archive/4.5.4.tar.gz && tar -xf 4.5.4.tar.gz && rm *.tar.gz -RUN cd && \ +ENV NVIDIA_DRIVER_CAPABILITIES compute,utility,graphics + + + +RUN cd ~/build && wget https://github.com/opencv/opencv/archive/4.5.4.tar.gz && tar -xf 4.5.4.tar.gz && rm 4.5.4.tar.gz +RUN cd ~/build && wget https://github.com/opencv/opencv_contrib/archive/4.5.4.tar.gz && tar -xf 4.5.4.tar.gz && rm 4.5.4.tar.gz +RUN cd ~/build && \ cd opencv-4.5.4 && mkdir build && cd build && \ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D INSTALL_C_EXAMPLES=OFF \ - -D OPENCV_EXTRA_MODULES_PATH='~/opencv_contrib-4.5.4/modules' \ + -D OPENCV_EXTRA_MODULES_PATH='~/build/opencv_contrib-4.5.4/modules' \ -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=OFF \ + -D BUILD_DOCS=OFF \ -D WITH_CUDA=ON \ + -D WITH_OPENGL=ON \ + -D WITH_NVCUVID=ON \ -D CUDA_ARCH_BIN=7.2 \ - -D CUDA_ARCH_PTX="" \ + -D CUDA_ARCH_PTX=7.2 \ -D ENABLE_FAST_MATH=ON \ -D CUDA_FAST_MATH=ON \ -D WITH_CUBLAS=ON \ + -D WITH_CUDNN=ON \ -D WITH_OPENMP=ON \ + -D WITH_NONFREE=ON \ -D WITH_LIBV4L=ON \ -D WITH_GSTREAMER=ON \ -D WITH_GSTREAMER_0_10=OFF \ -D WITH_TBB=ON \ - ../ && make -j12 && make install -RUN apt clean + ../ && make -j12 && make install && ldconfig +RUN cd ~ && rm -rf build +RUN cd ~ && mkdir Development && cd Development && \ +git clone https://github.com/ceccocats/tkDNN.git && cd tkDNN && \ +mkdir build && cd build && \ +cmake -DCMAKE_BUILD_TYPE=Release .. && \ +make -j6 + +RUN apt-get clean && rm -rf /var/lib/apt/lists/* +COPY assets/entrypoint_setup.sh / +ENTRYPOINT ["/entrypoint_setup.sh"] +CMD ["terminator"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index aec202a..15f3987 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,13 +9,10 @@ docker build -t tkdnn:build -f Dockerfile . # make nvidia docker working # follow this guide: https://github.com/NVIDIA/nvidia-docker -# dowload tensorrt -# from: https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb - # build image docker build -t ceccocats/tkdnn:latest -f Dockerfile.base . # run image -docker run -ti --gpus all --rm ceccocats/tkdnn:latest bash +./docker_launch.sh ``` diff --git a/docker/assets/entrypoint_setup.sh b/docker/assets/entrypoint_setup.sh new file mode 100755 index 0000000..348a4f5 --- /dev/null +++ b/docker/assets/entrypoint_setup.sh @@ -0,0 +1,123 @@ +#! /bin/bash + +CMD= + +# Functions +# TOOD: Check if we can use: getent passwd $USER to extract all variables +# TODO: Check for valid inputs, cause now it will go through even with bad inputs +check_envs () { + DOCKER_CUSTOM_USER_OK=true; + if [ -z ${DOCKER_USER_NAME+x} ]; then + DOCKER_CUSTOM_USER_OK=false; + return; + fi + + if [ -z ${DOCKER_USER_ID+x} ]; then + DOCKER_CUSTOM_USER_OK=false; + return; + else + if ! [ -z "${DOCKER_USER_ID##[0-9]*}" ]; then + echo -e "\033[1;33mWarning: User-ID should be a number. Falling back to defaults.\033[0m" + DOCKER_CUSTOM_USER_OK=false; + return; + fi + fi + + if [ -z ${DOCKER_USER_GROUP_NAME+x} ]; then + DOCKER_CUSTOM_USER_OK=false; + return; + fi + + if [ -z ${DOCKER_USER_GROUP_ID+x} ]; then + DOCKER_CUSTOM_USER_OK=false; + return; + else + if ! [ -z "${DOCKER_USER_GROUP_ID##[0-9]*}" ]; then + echo -e "\033[1;33mWarning: Group-ID should be a number. Falling back to defaults.\033[0m" + DOCKER_CUSTOM_USER_OK=false; + return; + fi + fi +} + +setup_env_user () { + USER=$1 + USER_ID=$2 + GROUP=$3 + GROUP_ID=$4 + + ## Create user + useradd -m $USER + + ## Copy zsh/sh configs + cp /root/.profile /home/$USER/ + cp /root/.bashrc /home/$USER/ + cp /root/.zshrc /home/$USER/ + ## Copy terminator configs + mkdir -p /home/$USER/.config/terminator + cp /root/.config/terminator/config /home/$USER/.config/terminator/config + cp /root/.config/terminator/background.png /home/$USER/.config/terminator/background.png + cp -rf /root/.oh-my-zsh /home/$USER/ + cp -rf /root/tkDNN /home/$USER/ + rm -rf /home/$USER/.oh-my-zsh/custom/pure.zsh-theme /home/$USER/.oh-my-zsh/custom/async.zsh + ln -s /home/$USER/.oh-my-zsh/custom/pure/pure.zsh-theme /home/$USER/.oh-my-zsh/custom/ + ln -s /home/$USER/.oh-my-zsh/custom/pure/async.zsh /home/$USER/.oh-my-zsh/custom/ + sed -i -e 's@ZSH=\"/root@ZSH=\"/home/$USER@g' /home/$USER/.zshrc + # Copy SSH keys & fix owner + if [ -d "/root/.ssh" ]; then + cp -rf /root/.ssh /home/$USER/ + chown -R $USER:$GROUP /home/$USER/.ssh + fi + + ## Fix owner + chown $USER:$GROUP /home/$USER + chown -R $USER:$GROUP /home/$USER/.config + chown $USER:$GROUP /home/$USER/.profile + chown $USER:$GROUP /home/$USER/.bashrc + chown $USER:$GROUP /home/$USER/.zshrc + chown -R $USER:$GROUP /home/$USER/.oh-my-zsh + chown -R $USER:$GROUP /home/$USER/tkDNN + + ## This a trick to keep the evnironmental variables of root which is important! + echo "if ! [ \"$DOCKER_USER_NAME\" = \"$(id -un)\" ]; then" >> /root/.bashrc + echo " cd /home/$DOCKER_USER_NAME" >> /root/.bashrc + echo " su $DOCKER_USER_NAME" >> /root/.bashrc + echo "fi" >> /root/.bashrc + + echo "if ! [ \"$DOCKER_USER_NAME\" = \"$(id -un)\" ]; then" >> /root/.zshrc + echo " cd /home/$DOCKER_USER_NAME" >> /root/.zshrc + echo " su $DOCKER_USER_NAME" >> /root/.zshrc + echo "fi" >> /root/.zshrc + + ## Setup Password-file + PASSWDCONTENTS=$(grep -v "^${USER}:" /etc/passwd) + GROUPCONTENTS=$(grep -v -e "^${GROUP}:" -e "^docker:" /etc/group) + + (echo "${PASSWDCONTENTS}" && echo "${USER}:x:$USER_ID:$GROUP_ID::/home/$USER:/bin/bash") > /etc/passwd + (echo "${GROUPCONTENTS}" && echo "${GROUP}:x:${GROUP_ID}:") > /etc/group + (if test -f /etc/sudoers ; then echo "${USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers ; fi) +} + + +# ---Main--- + +# Create new user +## Check Inputs +check_envs + +## Determine user & Setup Environment +if [ $DOCKER_CUSTOM_USER_OK == true ]; then + echo " -->DOCKER_USER Input is set to '$DOCKER_USER_NAME:$DOCKER_USER_ID:$DOCKER_USER_GROUP_NAME:$DOCKER_USER_GROUP_ID'"; + echo -e "\033[0;32mSetting up environment for user=$DOCKER_USER_NAME\033[0m" + setup_env_user $DOCKER_USER_NAME $DOCKER_USER_ID $DOCKER_USER_GROUP_NAME $DOCKER_USER_GROUP_ID +else + echo " -->DOCKER_USER* variables not set. Using 'root'."; + echo -e "\033[0;32mSetting up environment for user=root\033[0m" + DOCKER_USER_NAME="root" +fi + +# Change shell to zsh +chsh -s /usr/bin/zsh $DOCKER_USER_NAME + +# Run CMD from Docker +"$@" \ No newline at end of file diff --git a/docker/assets/terminator_config b/docker/assets/terminator_config new file mode 100644 index 0000000..d65a1b3 --- /dev/null +++ b/docker/assets/terminator_config @@ -0,0 +1,18 @@ +[global_config] + title_transmit_bg_color = "#2e3436" +[keybindings] +[layouts] + [[default]] + [[[child1]]] + parent = window0 + type = Terminal + [[[window0]]] + parent = "" + type = Window +[plugins] +[profiles] + [[default]] + background_color = "#282828" + cursor_color = "#aaaaaa" + foreground_color = "#f3f3f3" + palette = "#000000:#aa0000:#00aa00:#c4a000:#3465a4:#75507b:#06989a:#d3d7cf:#88807c:#f15d22:#73c48f:#ffce51:#48b9c7:#ad7fa8:#34e2e2:#eeeeec" diff --git a/docker/docker_launch.sh b/docker/docker_launch.sh new file mode 100755 index 0000000..24adb53 --- /dev/null +++ b/docker/docker_launch.sh @@ -0,0 +1,9 @@ +xhost local:root +docker run --rm -it --runtime=nvidia --privileged --net=host --cap-add sys_ptrace -d --ipc=host \ +-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY \ +-v $HOME/.Xauthority:/home/$(id -un)/.Xauthority -e XAUTHORITY=/home/$(id -un)/.Xauthority \ +-e DOCKER_USER_NAME=$(id -un) \ +-e DOCKER_USER_ID=$(id -u) \ +-e DOCKER_USER_GROUP_NAME=$(id -gn) \ +-e DOCKER_USER_GROUP_ID=$(id -g) \ +-v $HOME/.ssh:/home/$(id -un)/.ssh ceccocats/tkdnn diff --git a/docs/demo.md b/docs/demo.md index b14baf7..bf6b79d 100644 --- a/docs/demo.md +++ b/docs/demo.md @@ -30,31 +30,24 @@ cmake .. -DCMAKE_BUILD_TYPE=Debug -DDEBUG=True make ``` -Once you have successfully created your rt file, run the demo(yolo) : +Once you have successfully created your rt file, run the demo: ``` -./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y 80 ../tests/darknet/cfg/yolo4.cfg ../tests/darknet/names/coco.names +./ demo ``` +In general the demo program takes 1 parameter, the `````` that is the path to che configuration file. The parameter is optional and its default value is ```"../demo/demoConfig.yaml"```. -To run demo for mobilenet and centernet for the created rt file : -``` -./demo mobilenetv2ssd_fp32.rt m 20 -``` - -In general the demo program takes 7 parameters: -``` -./demo -``` -where - -* `````` is the rt file generated by a test -* ```<``` is the path to a video file or a camera input -* `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) -* ``````is the number of classes the network is trained on -* ``` ```is the relative path to the config file (only for darknet based networks) used to train the network -* ``````is the relative path to the names file (only for darknet based networks) used to train the network -* `````` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network). -* `````` if set to 0 the demo will not show the visualization but save the video into result.mp4 (if n-batches ==1) -* `````` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed. +The config file is a yaml file with the following attributes: +* ```net``` is the rt file generated by a test +* ```input``` is the path to a video file or a camera input (on Linux) +* ```win_input``` is the path to a video file or a camera input (on Windows) +* ```ntype``` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) +* ```n_classes``` is the number of classes the network is trained on +* ```n_batch``` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network). +* ```conf_thresh``` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed. +* ```show``` if set to 0 the demo will not show the visualization (if n-batches ==1) +* ```save``` if set to 1 the demo will save the video of the demo into result.mp4 (if n-batches ==1) +* ```cfg_input``` (for linux) \ ```cfg_win_input``` (for windows) is the location of the cfg path of the network for mobilenet and centernet networks use ```" "``` +* ```name_input``` (for linux) \ ```name_win_input``` (for windows) is the location of the name path of the network for mobilenet and centernet networks use ```" "``` N.B. By default it is used FP32 inference @@ -69,7 +62,8 @@ To run the demo with FP16 inference follow these steps (example with yolov3): export TKDNN_MODE=FP16 # set the half floating point optimization rm yolo4_fp16.rt # be sure to delete(or move) old tensorRT files ./test_yolo4 # run the yolo test (is slow) -./demo yolo4_fp16.rt ../demo/yolo_test.mp4 y 80 ../tests/darknet/cfg/yolo4.cfg ../tests/darknet/names/coco.names +#set net: yolo4_fp16.rt in the config file +./demo ``` N.B. Using FP16 inference will lead to some errors in the results (first or second decimal). @@ -94,7 +88,8 @@ export TKDNN_CALIB_LABEL_PATH=../demo/COCO_val2017/all_labels.txt export TKDNN_CALIB_IMG_PATH=../demo/COCO_val2017/all_images.txt rm yolo4_int8.rt # be sure to delete(or move) old tensorRT files ./test_yolo4 # run the yolo test (is slow) -./demo yolo4_int8.rt ../demo/yolo_test.mp4 y 80 ../tests/darknet/cfg/yolo4.cfg ../tests/darknet/names/coco.names +#set net: yolo4_int8.rt in the config file +./demo ``` N.B. diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index 1219ec3..a1a1f1c 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -6,6 +6,8 @@ #include #include #include +#include + #include "cuda.h" #include "cuda_runtime_api.h" @@ -16,7 +18,6 @@ #ifdef __linux__ #include - #endif #include @@ -161,5 +162,19 @@ static inline bool isCudaPointer(void *data) { return cudaPointerGetAttributes(&attr, data) == 0; } +inline YAML::Node YAMLloadConf(const std::string& conf_file) { + std::cerr<<"Loading YAML: "< +inline T YAMLgetConf(YAML::Node conf, std::string key, T defaultVal) { + T val = defaultVal; + if(conf && conf[key]) { + val = conf[key].as(); + } + return val; +} + #endif //UTILS_H diff --git a/scripts/checkExecTimes.py b/scripts/checkExecTimes.py new file mode 100644 index 0000000..c3e1b0b --- /dev/null +++ b/scripts/checkExecTimes.py @@ -0,0 +1,37 @@ +import sys +import pandas as pd + +if len(sys.argv) < 3: + print("Error: two csv files are needed, old first new second") + exit(1) + +old_perf_file = str(sys.argv[1]) +new_perf_file = str(sys.argv[2]) + +verbose = False +if len(sys.argv) == 4: + verbose = bool(sys.argv[3]) + +print("Comparing {} vs {}".format(old_perf_file, new_perf_file)) + +df_old = pd.read_csv (old_perf_file, sep=';', header=None, index_col=0) +df_new = pd.read_csv (new_perf_file, sep=';', header=None, index_col=0) + +for index, row in df_new.iterrows(): + if index in df_old.index: + if verbose: + print("New: ",row[1], row[2], row[3]) + print("Old: ",df_old.loc[index][1], df_old.loc[index][2], df_old.loc[index][3]) + + print(index, end=': ') + if abs(row[1] - df_old.loc[index][1]) < df_old.loc[index][1]*0.1: + print("similar performance") + elif (row[1] < df_old.loc[index][1]): + print('\x1b[3;30;42m' + 'faster' + '\x1b[0m') + elif (row[1] > df_old.loc[index][1]): + if row[1] > df_old.loc[index][1] + df_old.loc[index][1] * 0.5 : + print('\x1b[3;30;41m' + 'WAY SLOWER' + '\x1b[0m') + else: + print('\x1b[3;30;41m' + 'slower' + '\x1b[0m') + +