{
  "id": 132514,
  "title": "my problems about fastai ImageList",
  "url": "/competitions/bengaliai-cv19/discussion/132514",
  "author_name": "",
  "post_date": "2020-02-26T12:15:25.208461300Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I created a ndarray of train images( just parquet_0 and shape is(50210, 137, 236) learnt from public kernel =) ), and I subclass the fastai.ImageList like below(from fastai forum and amend little abour the 'get'). <br>\n```\nclass ArrayImageList(ImageList):\n    @classmethod\n    def from_numpy(cls, numpy_array):\n        return cls(items=range(len(numpy_array)), inner_df=numpy_array)</p>\n\n<pre><code>def label_from_array(self, array, label_cls=None, **kwargs):\n    return self._label_from_list(array[self.items.astype(np.int)], label_cls=label_cls, **kwargs)\n\ndef get(self, i):\n    n = self.inner_df[i]\n    n = n / n.max()\n    if n.ndim == 2:\n        h, w = n.shape\n        n = n.reshape(1, h, w)\n    n = torch.tensor(n).float()\n    return Image(n)\n</code></pre>\n\n<p><code>\nIt can work well and run <br>\n</code>data = (ArrayImageList.from_numpy(train_images)\n       .split_subsets(train_size=0.8, valid_size=0.2)\n       .label_from_array(train_labels[:len(train_images)])\n        .transform(get_transforms(), size=128)\n       .databunch(bs=10)\n        .normalize(stats)\n)\n``` <br>\nwithout any problem, but when I try data.show_batch(), I got this the picture below. <br>\nIs there the label lack in the center picture? Can any one hint me? Thank you very much! o-o </p>\n\n<p>What's more, the train_labels shape is (50210, 3) so I think I must do sth wrong with the code. But I counld't find it.</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3149580%2Fcabdadab45e237986f4517c493b18692%2FLabelLack.png?generation=1582719359716614&amp;alt=media\" alt=\"\"></p>",
  "messages": [
    {
      "id": "757083",
      "postDate": "02/26/2020 12:15:25",
      "content": "<p>I created a ndarray of train images( just parquet_0 and shape is(50210, 137, 236) learnt from public kernel =) ), and I subclass the fastai.ImageList like below(from fastai forum and amend little abour the 'get'). <br>\n```\nclass ArrayImageList(ImageList):\n    @classmethod\n    def from_numpy(cls, numpy_array):\n        return cls(items=range(len(numpy_array)), inner_df=numpy_array)</p>\n\n<pre><code>def label_from_array(self, array, label_cls=None, **kwargs):\n    return self._label_from_list(array[self.items.astype(np.int)], label_cls=label_cls, **kwargs)\n\ndef get(self, i):\n    n = self.inner_df[i]\n    n = n / n.max()\n    if n.ndim == 2:\n        h, w = n.shape\n        n = n.reshape(1, h, w)\n    n = torch.tensor(n).float()\n    return Image(n)\n</code></pre>\n\n<p><code>\nIt can work well and run <br>\n</code>data = (ArrayImageList.from_numpy(train_images)\n       .split_subsets(train_size=0.8, valid_size=0.2)\n       .label_from_array(train_labels[:len(train_images)])\n        .transform(get_transforms(), size=128)\n       .databunch(bs=10)\n        .normalize(stats)\n)\n``` <br>\nwithout any problem, but when I try data.show_batch(), I got this the picture below. <br>\nIs there the label lack in the center picture? Can any one hint me? Thank you very much! o-o </p>\n\n<p>What's more, the train_labels shape is (50210, 3) so I think I must do sth wrong with the code. But I counld't find it.</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3149580%2Fcabdadab45e237986f4517c493b18692%2FLabelLack.png?generation=1582719359716614&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "I created a ndarray of train images( just parquet_0 and shape is(50210, 137, 236) learnt from public kernel =) ), and I subclass the fastai.ImageList like below(from fastai forum and amend little abour the 'get').  \n```\nclass ArrayImageList(ImageList):\n    @classmethod\n    def from_numpy(cls, numpy_array):\n        return cls(items=range(len(numpy_array)), inner_df=numpy_array)\n    \n    def label_from_array(self, array, label_cls=None, **kwargs):\n        return self._label_from_list(array[self.items.astype(np.int)], label_cls=label_cls, **kwargs)\n    \n    def get(self, i):\n        n = self.inner_df[i]\n        n = n / n.max()\n        if n.ndim == 2:\n            h, w = n.shape\n            n = n.reshape(1, h, w)\n        n = torch.tensor(n).float()\n        return Image(n)\n```  \nIt can work well and run  \n```data = (ArrayImageList.from_numpy(train_images)\n       .split_subsets(train_size=0.8, valid_size=0.2)\n       .label_from_array(train_labels[:len(train_images)])\n        .transform(get_transforms(), size=128)\n       .databunch(bs=10)\n        .normalize(stats)\n)\n```  \nwithout any problem, but when I try data.show_batch(), I got this the picture below.  \nIs there the label lack in the center picture? Can any one hint me? Thank you very much! o-o \n \nWhat's more, the train_labels shape is (50210, 3) so I think I must do sth wrong with the code. But I counld't find it.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3149580%2Fcabdadab45e237986f4517c493b18692%2FLabelLack.png?generation=1582719359716614&amp;alt=media)",
      "votes": null
    },
    {
      "id": "760216",
      "postDate": "03/01/2020 01:31:38",
      "content": "<p>Because <code>.normalize(stats)</code>\nIf your variable <code>stats</code>  is  a 3-d vector, the output of images will expand to 3-d automatically...</p>",
      "rawMarkdown": "Because `.normalize(stats)`\nIf your variable `stats`  is  a 3-d vector, the output of images will expand to 3-d automatically...",
      "votes": null
    },
    {
      "id": "760221",
      "postDate": "03/01/2020 02:02:05",
      "content": "<p>Thank you! But my stats is ([0.0692], [0.2051]), and as I observed the output of show_batch, it's a little weird. So I do not care about the picture's title after I using mnist to check the labels assgin correctness.</p>",
      "rawMarkdown": "Thank you! But my stats is ([0.0692], [0.2051]), and as I observed the output of show_batch, it's a little weird. So I do not care about the picture's title after I using mnist to check the labels assgin correctness.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 760216,
      "author_name": "johnzdh",
      "author_url": "",
      "post_date": "03/01/2020 01:31:38",
      "content": "<p>Because <code>.normalize(stats)</code>\nIf your variable <code>stats</code>  is  a 3-d vector, the output of images will expand to 3-d automatically...</p>",
      "votes": null,
      "replies": [
        {
          "id": 760221,
          "author_name": "cnzengshiyuan",
          "author_url": "",
          "post_date": "03/01/2020 02:02:05",
          "content": "<p>Thank you! But my stats is ([0.0692], [0.2051]), and as I observed the output of show_batch, it's a little weird. So I do not care about the picture's title after I using mnist to check the labels assgin correctness.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "757083": "I created a ndarray of train images( just parquet_0 and shape is(50210, 137, 236) learnt from public kernel =) ), and I subclass the fastai.ImageList like below(from fastai forum and amend little abour the 'get').  \n```\nclass ArrayImageList(ImageList):\n    @classmethod\n    def from_numpy(cls, numpy_array):\n        return cls(items=range(len(numpy_array)), inner_df=numpy_array)\n    \n    def label_from_array(self, array, label_cls=None, **kwargs):\n        return self._label_from_list(array[self.items.astype(np.int)], label_cls=label_cls, **kwargs)\n    \n    def get(self, i):\n        n = self.inner_df[i]\n        n = n / n.max()\n        if n.ndim == 2:\n            h, w = n.shape\n            n = n.reshape(1, h, w)\n        n = torch.tensor(n).float()\n        return Image(n)\n```  \nIt can work well and run  \n```data = (ArrayImageList.from_numpy(train_images)\n       .split_subsets(train_size=0.8, valid_size=0.2)\n       .label_from_array(train_labels[:len(train_images)])\n        .transform(get_transforms(), size=128)\n       .databunch(bs=10)\n        .normalize(stats)\n)\n```  \nwithout any problem, but when I try data.show_batch(), I got this the picture below.  \nIs there the label lack in the center picture? Can any one hint me? Thank you very much! o-o \n \nWhat's more, the train_labels shape is (50210, 3) so I think I must do sth wrong with the code. But I counld't find it.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3149580%2Fcabdadab45e237986f4517c493b18692%2FLabelLack.png?generation=1582719359716614&amp;alt=media)",
    "760216": "Because `.normalize(stats)`\nIf your variable `stats`  is  a 3-d vector, the output of images will expand to 3-d automatically...",
    "760221": "Thank you! But my stats is ([0.0692], [0.2051]), and as I observed the output of show_batch, it's a little weird. So I do not care about the picture's title after I using mnist to check the labels assgin correctness."
  },
  "source": "meta"
}