{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import csv\nimport os\nimport numpy as np\nimport shutil","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_train_label = '../input/labels/train_label.csv'\na_test_label = '../input/labels/test_label.csv'","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''将图片按照label文件分别拷贝进train_image和test_image目录内'''\nall_image = '../input/cassava-leaf-disease-classification/train_images'\ntrain_image = './train_image'\ntest_image = './test_image'\nos.mkdir(train_image)\nos.mkdir(test_image)\ntr_label = []\nte_label = []\ntrain_data = []\ntest_data = []","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 读取csv数据\nwith open(a_train_label)as train_file:\n    train_reader = csv.reader(train_file)\n    tr_label = next(train_reader)\n    for row in train_reader:\n        train_data.append(row)\nwith open(a_test_label)as test_file:\n    test_reader = csv.reader(test_file)\n    te_label = next(test_reader)\n    for row in test_reader:\n        test_data.append(row)\n\n# 生成训练数据集\nfor row in train_data:\n    shutil.copyfile(os.path.join(all_image, row[0]),os.path.join(train_image, row[0]))\n\n\n# 生成测试数据集\nfor row in test_data:\n    shutil.copyfile(os.path.join(all_image, row[0]),os.path.join(test_image, row[0]))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.copyfile('../input/labels/test_label.csv' , './test_labels.csv')\nshutil.copyfile('../input/labels/train_label.csv' , './train_labels.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patha, dirsa, filesa = next(os.walk(\"./train_image\"))\nprint(len(filesa))\npathb, dirsb, filesb = next(os.walk(\"./test_image\"))\nprint(len(filesb))","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}