{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84969,"databundleVersionId":10033515,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":104.820086,"end_time":"2024-12-05T09:07:06.020274","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-12-05T09:05:21.200188","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Intro\n\nIn this notebook I try to explain (primary to myself) the core idea of a notebook \nusing code:\n\nthe notebook I try to understand is \nhttps://www.kaggle.com/code/itsuki9180/czii-making-datasets-for-yolo\n\nThe core function is `make_annotate_yolo`\n\nRember I'm not an expert on the field so take this not just \nas a shared understanding execize which could contain important error","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"def make_annotate_yolo(run_name, for_train=True):\n    # to split validation\n    split_name = 'train' if for_train, else 'val'\n    vols = zarr.open(f'/kaggle/input/czii-cryo-et-object-identification/train/static/ExperimentRuns/{run_name}/VoxelSpacing10.000/denoised.zarr', mode='r')\n    # use largest images\n    vol = vols[0]\n    # normalize [0, 255]\n    vol_8bit = convert_to_8bit(vol)\n    depth_pixel = vol_8bit.shape[0]\n    for z_pixel in range(depth_pixel):\n        slice_ = vol_8bit[z]\n        yolo_slice = to_yolo_slice(slice_)\n        z_mm = z_pixel*10\n        slice_name = f'{run_name}_{z_mm}'\n        write_slice_image(split_name, slice_name, yolo_slice)\n        init_slice_annotation(split_name, slice_name)\n\n\n    # process each paticle types\n    for p, particle in enumerate(tqdm(particle_names)):\n        # we do not have to detect beta-amylase which weight is 0\n        if particle==\"beta-amylase\":\n            continue\n\n        df = get_particle_annotation_df(run_name, particle)\n\n        radius_mm = particle_radius[particle]\n\n        for i, particle_info in df.iterrows():\n            x_mm = particle_info['x']\n            y_mm = particle_info['y']\n            z_mm = particle_info['z']\n            start_z_pixel, end_z_pixel = find_slide_range(z_mm, radius_mm, depth_pixel)\n            for z_pixel in range(start_z_pixel, end_z_pixel, 1):\n\n                z_mm = z_pixel*10\n                slice_name = f'{run_name}_{z_mm}'\n\n                width_pixel = vol_8bit.shape[1]\n                height_pixel = vol_8bit.shape[0]\n\n                add_slice_annotation(split_name, slice_name, particle, x_mm, y_mm, radius_mm, width_pixel, height_pixel)\n","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}