{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport cv2 as cv\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"os.listdir('/kaggle/input/faster-submission')\n# cascade-submission-result\n# faster-submission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"cascade = '/kaggle/input/cascade-submission-result/submission.csv'\nfaster = '/kaggle/input/faster-submission/submission .csv'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def string2bbox(result_string):\n    results = result_string.split(' ')\n    assert len(results) % 5 == 0\n    results = np.array(results, dtype=str)\n    results = results.reshape(-1, 5)\n    return results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def show_csv_result(csv_file):\n    df = pd.read_csv(csv_file)\n    results = df['PredictionString']\n    for idx in range(len(df)):\n        item = df.iloc[idx]\n        image_name, bbox = item\n        image_path = f'/kaggle/input/global-wheat-detection/test/{image_name}.jpg'\n        image = cv.imread(image_path)\n        assert image is not None\n        bbox = string2bbox(bbox)\n        for single_box in bbox:\n            score = float(single_box[0])\n            _box = list(map(float, single_box[1:]))\n            _box = list(map(round, _box))\n            x, y, w, h = _box\n            cv.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)\n        submission_info = csv_file.split('/')[-2]\n        save_path = f'/kaggle/working/vis_results/{submission_info}'\n        if not os.path.exists(save_path):\n            os.makedirs(save_path)\n        cv.imwrite(f'{save_path}/{image_name}.jpg', image)\n            ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!rm -rf /kaggle/working/vis_results\nshow_csv_result(cascade)\nshow_csv_result(faster)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!zip -r vis_results.zip /kaggle/working/vis_results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}