{"cells":[{"metadata":{"_uuid":"967e520d01f6a891fd509f252bfcc551b84354d1"},"cell_type":"markdown","source":"# Dataset of non nuclei images\n\nWe prepared a small dataset of images that contain no nuclei and can be added to training in order to help your model deal with some artifacts."},{"metadata":{"trusted":true,"_uuid":"83bc216b0cd379cf5ca20920cb98434609f1f2ff"},"cell_type":"code","source":"%matplotlib inline\n%load_ext autoreload\n%autoreload 2\n\nimport math\nimport matplotlib.pyplot as plt\nfrom sklearn.externals import joblib\n\ndef plot_list(images=[], labels=[], n_rows=1):\n    n_img = len(images)\n    n_lab = len(labels)\n    n_cols = math.ceil((n_lab+n_img)/n_rows)\n    plt.figure(figsize=(16,10))\n    for i, image in enumerate(images):\n        plt.subplot(n_rows,n_cols,i+1)\n        plt.imshow(image)\n    for j, label in enumerate(labels):\n        plt.subplot(n_rows,n_cols,n_img+j+1)\n        plt.imshow(label, cmap='nipy_spectral')\n    plt.show()","execution_count":19,"outputs":[]},{"metadata":{"collapsed":true,"trusted":true,"_uuid":"349424dc1fafae57d6db39fc4aa4973df8768d4c"},"cell_type":"code","source":"non_nuclei_images = joblib.load('../input/non-nuclei-images/non_nuclei_images.pkl')","execution_count":20,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f26426cc3b5153add8f2c38c1074af82932545e5"},"cell_type":"code","source":"plot_list(non_nuclei_images, n_rows=4)","execution_count":21,"outputs":[]},{"metadata":{"_uuid":"28559e4652f82839f6dc90750704b21695a3d4ef"},"cell_type":"markdown","source":"# Full pipeline\nIf you would like to see how we plugged this data in just go to our [open solution](https://github.com/neptune-ml/open-solution-data-science-bowl-2018)\n\n![full open solution pipeline](https://gist.githubusercontent.com/jakubczakon/10e5eb3d5024cc30cdb056d5acd3d92f/raw/e85c1da3acfe96123d0ff16f8145913ee65e938c/full_pipeline.png)\n\nIn the `main.py` of the `dev-patching` branch we have a function that generates metadata that looks like this:\n\n```python\n@action.command()\ndef prepare_metadata():\n    logger.info('creating metadata')\n    meta = generate_metadata(data_dir=params.data_dir,\n                             masks_overlayed_dir=params.masks_overlayed_dir,\n                             contours_overlayed_dir=params.contours_overlayed_dir,\n                             contours_touching_overlayed_dir=params.contours_touching_overlayed_dir,\n                             centers_overlayed_dir=params.centers_overlayed_dir)\n    logger.info('calculating clusters')\n    meta_train = meta[meta['is_train'] == 1]\n    meta_test = meta[meta['is_train'] == 0]\n    vgg_features_clusters = get_vgg_clusters(meta_train)\n    meta_train['vgg_features_clusters'] = vgg_features_clusters\n    meta_test['vgg_features_clusters'] = 'NaN'\n    meta = pd.concat([meta_train, meta_test], axis=0)\n\n    logger.info('adding artifacts metadata')\n    meta_artifacts = build_artifacts_metadata(artifacts_dir=params.artifacts_dir)\n    meta = pd.concat([meta, meta_artifacts], axis=0)\n\n    meta.to_csv(os.path.join(params.meta_dir, 'stage1_metadata.csv'), index=None)\n```\n\nFeel free to use it in your solution.\nGood luck!"},{"metadata":{"collapsed":true,"trusted":true,"_uuid":"8e251d80259fc73738d304a966add64260ae1a3c"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}