{"action":"created","issue":{"url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/4","repository_url":"https://api.github.com/repos/wolny/pytorch-3dunet","labels_url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/4/comments","events_url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/4/events","html_url":"https://github.com/wolny/pytorch-3dunet/issues/4","id":383069677,"node_id":"MDU6SXNzdWUzODMwNjk2Nzc=","number":4,"title":"[Question] How to create the target tensor for my own data?","user":{"login":"farazkhan86","id":44167893,"node_id":"MDQ6VXNlcjQ0MTY3ODkz","avatar_url":"https://avatars3.githubusercontent.com/u/44167893?v=4","gravatar_id":"","url":"https://api.github.com/users/farazkhan86","html_url":"https://github.com/farazkhan86","followers_url":"https://api.github.com/users/farazkhan86/followers","following_url":"https://api.github.com/users/farazkhan86/following{/other_user}","gists_url":"https://api.github.com/users/farazkhan86/gists{/gist_id}","starred_url":"https://api.github.com/users/farazkhan86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/farazkhan86/subscriptions","organizations_url":"https://api.github.com/users/farazkhan86/orgs","repos_url":"https://api.github.com/users/farazkhan86/repos","events_url":"https://api.github.com/users/farazkhan86/events{/privacy}","received_events_url":"https://api.github.com/users/farazkhan86/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-21T11:14:07Z","updated_at":"2018-12-01T17:44:08Z","closed_at":"2018-11-26T18:52:54Z","author_association":"NONE","body":"Hi, \r\nMany thanks for providing this framework for 3D CNN. Its a huge help for people like myself who are trying to teach them self deep learning with volumetric data. \r\n\r\nI understand the working of your code and also got it to run on the random data but I am struggling with how to create the target tensor for my 3D data. I taught myself semantic segmentation with 2D data using the CamVid dataset. And I understood the process of labeling for semantic segmentation for 2D images. I was able to create label or target tensors using a colour coded method provided for the dataset. The colour codes provided were:\r\n\r\n```\r\n    (\"Animal\", np.array([64, 128, 64], dtype=np.uint8)),\r\n    (\"Archway\", np.array([192, 0, 128], dtype=np.uint8)),\r\n    (\"Bicyclist\", np.array([0, 128, 192], dtype=np.uint8)),\r\n    (\"Bridge\", np.array([0, 128, 64], dtype=np.uint8)),\r\n    (\"Building\", np.array([128, 0, 0], dtype=np.uint8)),\r\n    (\"Car\", np.array([64, 0, 128], dtype=np.uint8)),\r\n    (\"CartLuggagePram\", np.array([64, 0, 192], dtype=np.uint8)),\r\n    (\"Child\", np.array([192, 128, 64], dtype=np.uint8)),\r\n```\r\n\r\nTo create a label for my network I would simply locate these RGB colours in the images and compare each \"object\" with its respective colour code and then give it a value in a grayscale image. So each label would be a single channel tensor. And the output of my system would have channels equal to the number of classes in the dataset (for CamVid this was 32).\r\n\r\nNo I am trying to do the same in 3D and am struggling to understand what to do. The problem is a binary one as I have to detect a single item in the input so basically I should have two output channels: Background and foreground. I have a 3D single channel input, the input having the shape: ``[BS, Channel, Z, X, Y]``. \r\n\r\nFor this input, I have a tensor which indicates the locations of my object of interest in the input. A 3D Gaussian is built around each point to be measured. \r\n\r\nI hope I have explained my situation clearly.\r\n\r\nMy confusion is how to create a label tensor in 3D for segmenting my points of interest as I have done for the CamVid dataset.\r\n\r\nBelow is a 2D representation of a target that has 3D Gaussians drawn on the points of interest, the tensor is of the size ``[16, 64, 64]``\r\n\r\n![target](https://user-images.githubusercontent.com/44167893/48837877-776b8f00-ed7e-11e8-9a19-0170ce282e20.png)\r\n\r\n\r\nHere is the target file as a pickle dump (just in case): https://app.box.com/s/movmlt377991ptrpd0kug0d3d8s85q9l\r\n\r\nSimilar to the CamVid case as I would have 1 channel per class, here I know that I would have 2 channels, one for the background and 1 for the foreground, but how to label these 3D tensors is what I dont understand."},"comment":{"url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/comments/443444098","html_url":"https://github.com/wolny/pytorch-3dunet/issues/4#issuecomment-443444098","issue_url":"https://api.github.com/repos/wolny/pytorch-3dunet/issues/4","id":443444098,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MzQ0NDA5OA==","user":{"login":"wolny","id":706781,"node_id":"MDQ6VXNlcjcwNjc4MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/706781?v=4","gravatar_id":"","url":"https://api.github.com/users/wolny","html_url":"https://github.com/wolny","followers_url":"https://api.github.com/users/wolny/followers","following_url":"https://api.github.com/users/wolny/following{/other_user}","gists_url":"https://api.github.com/users/wolny/gists{/gist_id}","starred_url":"https://api.github.com/users/wolny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolny/subscriptions","organizations_url":"https://api.github.com/users/wolny/orgs","repos_url":"https://api.github.com/users/wolny/repos","events_url":"https://api.github.com/users/wolny/events{/privacy}","received_events_url":"https://api.github.com/users/wolny/received_events","type":"User","site_admin":false},"created_at":"2018-12-01T17:44:08Z","updated_at":"2018-12-01T17:44:08Z","author_association":"OWNER","body":"Hey @farazkhan86,\r\n\r\nre the HDF5 backed dataset: while creating it you need to provide the file system path to the raw data and label data, as well as internal H5 path for the raw and label (if the internal is not provided the implementation will try to load `/raw` dataset as the raw data and `/label` dataset for the label).\r\nE.g. having a training file in your `/home/user/datasets/train.h5`\r\n```\r\n/volume #raw data\r\n/target #lable data\r\n```\r\nyou can create the `HDF5Dataset` by `HDF5Dataset('/home/user/datasets/train.h5', patch_shape=..., stride_shape=..., raw_internal_path='/volume', label_internal_path='/target')` (bear in mind that both raw and label are in the same H5 file in this case.\r\n\r\nIf you 500 3D volumes, each in different H5 file, I'd recommend using the `torch.utils.data.ConcatDataset` so that you don't have to create this additional giant H5 with all the training data in it. E.g. use something like:\r\n```\r\nh5_datasets = []\r\nfor i in range(500):\r\n  h5_datasets.append(HDF5Dataset(f'file{i}.h5', ...))\r\n\r\nresult = ConcatDataset(h5_datasets)\r\n```\r\n\r\n`RandomRotate90` tranformer is implemented correctly even for 4D tensors, look closely: `m` is 4D `m[c]` is 3D, so `np.rot90(m[c], k, (1, 2))` is correct."}}
{"actor":{"display_login":"wolny"}}