From 53e092fa0cc9a9c24d1932802e14265f308cbe0d Mon Sep 17 00:00:00 2001 From: Daniel Bourke Date: Fri, 19 Nov 2021 13:00:25 +1000 Subject: [PATCH] update pytorch custom dataset code --- 04_pytorch_custom_datasets.ipynb | 59 ++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/04_pytorch_custom_datasets.ipynb b/04_pytorch_custom_datasets.ipynb index cc960d1..ed5b200 100644 --- a/04_pytorch_custom_datasets.ipynb +++ b/04_pytorch_custom_datasets.ipynb @@ -1218,10 +1218,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import os\n", + "def walk_through_dir(dir_path):\n", + " \"\"\"\n", + " Walks through dir_path returning its contents.\n", + " Args:\n", + " dir_path (str): target directory\n", + " \n", + " Returns:\n", + " A print out of:\n", + " number of subdiretories in dir_path\n", + " number of images (files) in each subdirectory\n", + " name of each subdirectory\n", + " \"\"\"\n", + " for dirpath, dirnames, filenames in os.walk(dir_path):\n", + " print(f\"There are {len(dirnames)} directories and {len(filenames)} images in '{dirpath}'.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 2 directories and 1 images in '10_whole_foods'.\n", + "There are 10 directories and 0 images in '10_whole_foods/test'.\n", + "There are 0 directories and 17 images in '10_whole_foods/test/carrots'.\n", + "There are 0 directories and 11 images in '10_whole_foods/test/mushrooms'.\n", + "There are 0 directories and 17 images in '10_whole_foods/test/apple'.\n", + "There are 0 directories and 10 images in '10_whole_foods/test/strawberries'.\n", + "There are 0 directories and 19 images in '10_whole_foods/test/blueberries'.\n", + "There are 0 directories and 20 images in '10_whole_foods/test/banana'.\n", + "There are 0 directories and 21 images in '10_whole_foods/test/beef'.\n", + "There are 0 directories and 15 images in '10_whole_foods/test/egg'.\n", + "There are 0 directories and 19 images in '10_whole_foods/test/honey'.\n", + "There are 0 directories and 15 images in '10_whole_foods/test/chicken_wings'.\n", + "There are 10 directories and 0 images in '10_whole_foods/train'.\n", + "There are 0 directories and 70 images in '10_whole_foods/train/carrots'.\n", + "There are 0 directories and 66 images in '10_whole_foods/train/mushrooms'.\n", + "There are 0 directories and 57 images in '10_whole_foods/train/apple'.\n", + "There are 0 directories and 64 images in '10_whole_foods/train/strawberries'.\n", + "There are 0 directories and 59 images in '10_whole_foods/train/blueberries'.\n", + "There are 0 directories and 58 images in '10_whole_foods/train/banana'.\n", + "There are 0 directories and 74 images in '10_whole_foods/train/beef'.\n", + "There are 0 directories and 65 images in '10_whole_foods/train/egg'.\n", + "There are 0 directories and 63 images in '10_whole_foods/train/honey'.\n", + "There are 0 directories and 78 images in '10_whole_foods/train/chicken_wings'.\n" + ] + } + ], + "source": [ + "walk_through_dir(\"10_whole_foods\")" + ] }, { "cell_type": "code",