{
  "id": 48615,
  "title": "How could I use 'next' function in win10? ",
  "url": "/competitions/data-science-bowl-2018/discussion/48615",
  "author_name": "",
  "post_date": "2018-01-30T14:53:46.389928500Z",
  "votes": null,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I'm a greenhand for computer vision.\nI use the following in win10 to read data: </p>\n\n<p>train_ids = next(os.walk(TRAIN_PATH))[1]</p>\n\n<p>test_ids = next(os.walk(TEST_PATH))[1]</p>\n\n<p>but there is a 'Stopiteration' error. \nI can use this in Linux without any error. Why? \nWould there be anybody to help me? Thanks a lot!</p>",
  "messages": [
    {
      "id": "276040",
      "postDate": "01/30/2018 14:53:46",
      "content": "<p>I'm a greenhand for computer vision.\nI use the following in win10 to read data: </p>\n\n<p>train_ids = next(os.walk(TRAIN_PATH))[1]</p>\n\n<p>test_ids = next(os.walk(TEST_PATH))[1]</p>\n\n<p>but there is a 'Stopiteration' error. \nI can use this in Linux without any error. Why? \nWould there be anybody to help me? Thanks a lot!</p>",
      "rawMarkdown": "I'm a greenhand for computer vision.\nI use the following in win10 to read data: \n\ntrain_ids = next(os.walk(TRAIN_PATH))[1]\n\ntest_ids = next(os.walk(TEST_PATH))[1]\n\nbut there is a 'Stopiteration' error. \nI can use this in Linux without any error. Why? \nWould there be anybody to help me? Thanks a lot!",
      "votes": null
    },
    {
      "id": "276240",
      "postDate": "01/31/2018 02:47:24",
      "content": "<p>code runs ok on my win10 &amp;python3\nmaybe the different path format cause error ?\nwhat is in TRAIN_PATH ?</p>",
      "rawMarkdown": "code runs ok on my win10 &amp;python3\nmaybe the different path format cause error ?\nwhat is in TRAIN_PATH ?",
      "votes": null
    },
    {
      "id": "276266",
      "postDate": "01/31/2018 03:30:05",
      "content": "<p>I use the following code, and now in  'train_ids = next(os.walk(train_path))[1]' there is no error</p>\n\n<p>but in ' for mask_file in next(os.walk(path1))[2]:' still have a  'Stopiteration' error.</p>\n\n<pre><code>train_path = 'D:\\\\kaggle\\\\stage1_test'\ntest_path = 'D:\\\\kaggle\\\\stage1_train'\n\ndef make_df(train_path, test_path, img_size):\n    train_ids = next(os.walk(train_path))[1]\n    test_ids = next(os.walk(test_path))[1]\n    X_train = np.zeros((len(train_ids), img_size, img_size, 3), dtype=np.uint8)\n    Y_train = np.zeros((len(train_ids), img_size, img_size, 1), dtype=np.bool)\n    for i, id_ in enumerate(train_ids):\n        path = train_path +'\\\\'+ id_\n        img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n        img = cv2.resize(img, (img_size, img_size))\n        X_train[i] = img\n        mask = np.zeros((img_size, img_size, 1), dtype=np.bool)\n        path1 = path + '\\\\'+'masks'\n        print(path1)\n        for mask_file in next(os.walk(path1))[2]:\n            mask_ = cv2.imread(path + '\\\\masks\\\\' + mask_file, 0)\n            mask_ = cv2.resize(mask_, (img_size, img_size))\n            mask_ = mask_[:, :, np.newaxis]\n            mask = np.maximum(mask, mask_)\n        Y_train[i] = mask\n    X_test = np.zeros((len(test_ids), img_size, img_size, 3), dtype=np.uint8)\n    sizes_test = []\n    for i, id_ in enumerate(test_ids):\n        path = test_path + id_\n        img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n        sizes_test.append([img.shape[0], img.shape[1]])\n        img = cv2.resize(img, (img_size, img_size))\n        X_test[i] = img\nreturn X_train, Y_train, X_test, sizes_test\n</code></pre>",
      "rawMarkdown": "I use the following code, and now in  'train_ids = next(os.walk(train_path))[1]' there is no error\n\n but in ' for mask_file in next(os.walk(path1))[2]:' still have a  'Stopiteration' error.\n\n    train_path = 'D:\\\\kaggle\\\\stage1_test'\n    test_path = 'D:\\\\kaggle\\\\stage1_train'\n       \n    def make_df(train_path, test_path, img_size):\n        train_ids = next(os.walk(train_path))[1]\n        test_ids = next(os.walk(test_path))[1]\n        X_train = np.zeros((len(train_ids), img_size, img_size, 3), dtype=np.uint8)\n        Y_train = np.zeros((len(train_ids), img_size, img_size, 1), dtype=np.bool)\n        for i, id_ in enumerate(train_ids):\n            path = train_path +'\\\\'+ id_\n            img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n            img = cv2.resize(img, (img_size, img_size))\n            X_train[i] = img\n            mask = np.zeros((img_size, img_size, 1), dtype=np.bool)\n            path1 = path + '\\\\'+'masks'\n            print(path1)\n            for mask_file in next(os.walk(path1))[2]:\n                mask_ = cv2.imread(path + '\\\\masks\\\\' + mask_file, 0)\n                mask_ = cv2.resize(mask_, (img_size, img_size))\n                mask_ = mask_[:, :, np.newaxis]\n                mask = np.maximum(mask, mask_)\n            Y_train[i] = mask\n        X_test = np.zeros((len(test_ids), img_size, img_size, 3), dtype=np.uint8)\n        sizes_test = []\n        for i, id_ in enumerate(test_ids):\n            path = test_path + id_\n            img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n            sizes_test.append([img.shape[0], img.shape[1]])\n            img = cv2.resize(img, (img_size, img_size))\n            X_test[i] = img\n    return X_train, Y_train, X_test, sizes_test",
      "votes": null
    },
    {
      "id": "276301",
      "postDate": "01/31/2018 06:00:37",
      "content": "<p>bug here: \ntrain_path = 'D:\\kaggle\\stage1_test'\ntest_path = 'D:\\kaggle\\stage1_train'\nno masks folder in stage1_test!!!</p>",
      "rawMarkdown": "bug here: \ntrain_path = 'D:\\\\kaggle\\\\stage1_test'\ntest_path = 'D:\\\\kaggle\\\\stage1_train'\nno masks folder in stage1_test!!!",
      "votes": null
    },
    {
      "id": "276302",
      "postDate": "01/31/2018 06:05:31",
      "content": "<p>Thanks a lot. I miss this little bug!</p>",
      "rawMarkdown": "Thanks a lot. I miss this little bug!",
      "votes": null
    },
    {
      "id": "288659",
      "postDate": "02/28/2018 00:51:25",
      "content": "<p>Hello @KG123, can you elaborate more on the correct path if there are bugs in train_path = 'D:\\kaggle\\stage1_test' test_path = 'D:\\kaggle\\stage1_train' ? Thanks!!</p>",
      "rawMarkdown": "Hello @KG123, can you elaborate more on the correct path if there are bugs in train_path = 'D:\\kaggle\\stage1_test' test_path = 'D:\\kaggle\\stage1_train' ? Thanks!!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 276240,
      "author_name": "kga1a2y3",
      "author_url": "",
      "post_date": "01/31/2018 02:47:24",
      "content": "<p>code runs ok on my win10 &amp;python3\nmaybe the different path format cause error ?\nwhat is in TRAIN_PATH ?</p>",
      "votes": null,
      "replies": [
        {
          "id": 276266,
          "author_name": "zj730622",
          "author_url": "",
          "post_date": "01/31/2018 03:30:05",
          "content": "<p>I use the following code, and now in  'train_ids = next(os.walk(train_path))[1]' there is no error</p>\n\n<p>but in ' for mask_file in next(os.walk(path1))[2]:' still have a  'Stopiteration' error.</p>\n\n<pre><code>train_path = 'D:\\\\kaggle\\\\stage1_test'\ntest_path = 'D:\\\\kaggle\\\\stage1_train'\n\ndef make_df(train_path, test_path, img_size):\n    train_ids = next(os.walk(train_path))[1]\n    test_ids = next(os.walk(test_path))[1]\n    X_train = np.zeros((len(train_ids), img_size, img_size, 3), dtype=np.uint8)\n    Y_train = np.zeros((len(train_ids), img_size, img_size, 1), dtype=np.bool)\n    for i, id_ in enumerate(train_ids):\n        path = train_path +'\\\\'+ id_\n        img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n        img = cv2.resize(img, (img_size, img_size))\n        X_train[i] = img\n        mask = np.zeros((img_size, img_size, 1), dtype=np.bool)\n        path1 = path + '\\\\'+'masks'\n        print(path1)\n        for mask_file in next(os.walk(path1))[2]:\n            mask_ = cv2.imread(path + '\\\\masks\\\\' + mask_file, 0)\n            mask_ = cv2.resize(mask_, (img_size, img_size))\n            mask_ = mask_[:, :, np.newaxis]\n            mask = np.maximum(mask, mask_)\n        Y_train[i] = mask\n    X_test = np.zeros((len(test_ids), img_size, img_size, 3), dtype=np.uint8)\n    sizes_test = []\n    for i, id_ in enumerate(test_ids):\n        path = test_path + id_\n        img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n        sizes_test.append([img.shape[0], img.shape[1]])\n        img = cv2.resize(img, (img_size, img_size))\n        X_test[i] = img\nreturn X_train, Y_train, X_test, sizes_test\n</code></pre>",
          "votes": null,
          "replies": []
        },
        {
          "id": 276301,
          "author_name": "kga1a2y3",
          "author_url": "",
          "post_date": "01/31/2018 06:00:37",
          "content": "<p>bug here: \ntrain_path = 'D:\\kaggle\\stage1_test'\ntest_path = 'D:\\kaggle\\stage1_train'\nno masks folder in stage1_test!!!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 276302,
          "author_name": "zj730622",
          "author_url": "",
          "post_date": "01/31/2018 06:05:31",
          "content": "<p>Thanks a lot. I miss this little bug!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 288659,
          "author_name": "chvbs2000",
          "author_url": "",
          "post_date": "02/28/2018 00:51:25",
          "content": "<p>Hello @KG123, can you elaborate more on the correct path if there are bugs in train_path = 'D:\\kaggle\\stage1_test' test_path = 'D:\\kaggle\\stage1_train' ? Thanks!!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "276040": "I'm a greenhand for computer vision.\nI use the following in win10 to read data: \n\ntrain_ids = next(os.walk(TRAIN_PATH))[1]\n\ntest_ids = next(os.walk(TEST_PATH))[1]\n\nbut there is a 'Stopiteration' error. \nI can use this in Linux without any error. Why? \nWould there be anybody to help me? Thanks a lot!",
    "276240": "code runs ok on my win10 &amp;python3\nmaybe the different path format cause error ?\nwhat is in TRAIN_PATH ?",
    "276266": "I use the following code, and now in  'train_ids = next(os.walk(train_path))[1]' there is no error\n\n but in ' for mask_file in next(os.walk(path1))[2]:' still have a  'Stopiteration' error.\n\n    train_path = 'D:\\\\kaggle\\\\stage1_test'\n    test_path = 'D:\\\\kaggle\\\\stage1_train'\n       \n    def make_df(train_path, test_path, img_size):\n        train_ids = next(os.walk(train_path))[1]\n        test_ids = next(os.walk(test_path))[1]\n        X_train = np.zeros((len(train_ids), img_size, img_size, 3), dtype=np.uint8)\n        Y_train = np.zeros((len(train_ids), img_size, img_size, 1), dtype=np.bool)\n        for i, id_ in enumerate(train_ids):\n            path = train_path +'\\\\'+ id_\n            img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n            img = cv2.resize(img, (img_size, img_size))\n            X_train[i] = img\n            mask = np.zeros((img_size, img_size, 1), dtype=np.bool)\n            path1 = path + '\\\\'+'masks'\n            print(path1)\n            for mask_file in next(os.walk(path1))[2]:\n                mask_ = cv2.imread(path + '\\\\masks\\\\' + mask_file, 0)\n                mask_ = cv2.resize(mask_, (img_size, img_size))\n                mask_ = mask_[:, :, np.newaxis]\n                mask = np.maximum(mask, mask_)\n            Y_train[i] = mask\n        X_test = np.zeros((len(test_ids), img_size, img_size, 3), dtype=np.uint8)\n        sizes_test = []\n        for i, id_ in enumerate(test_ids):\n            path = test_path + id_\n            img = cv2.imread(path + '\\\\images\\\\' + id_ + '.png')\n            sizes_test.append([img.shape[0], img.shape[1]])\n            img = cv2.resize(img, (img_size, img_size))\n            X_test[i] = img\n    return X_train, Y_train, X_test, sizes_test",
    "276301": "bug here: \ntrain_path = 'D:\\\\kaggle\\\\stage1_test'\ntest_path = 'D:\\\\kaggle\\\\stage1_train'\nno masks folder in stage1_test!!!",
    "276302": "Thanks a lot. I miss this little bug!",
    "288659": "Hello @KG123, can you elaborate more on the correct path if there are bugs in train_path = 'D:\\kaggle\\stage1_test' test_path = 'D:\\kaggle\\stage1_train' ? Thanks!!"
  },
  "source": "meta"
}