This commit is contained in:
s444519 2022-06-07 22:42:35 +02:00
parent fb2e70e1da
commit 8e4927d3ea
3 changed files with 210 additions and 73 deletions

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 54,
"id": "f902472d", "id": "f902472d",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 55,
"id": "2324a8dd", "id": "2324a8dd",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -35,7 +35,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 56,
"id": "e4ba4b52", "id": "e4ba4b52",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -144,7 +144,7 @@
"9 2017.005479 20170103 Sinn Féin warns Stormont may collapse over 'ca..." "9 2017.005479 20170103 Sinn Féin warns Stormont may collapse over 'ca..."
] ]
}, },
"execution_count": 30, "execution_count": 56,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -155,7 +155,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 57,
"id": "d4a64cb8", "id": "d4a64cb8",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -264,7 +264,7 @@
"9 2012.791781 20121016 UK investigation into Icelandic bank fraud aba..." "9 2012.791781 20121016 UK investigation into Icelandic bank fraud aba..."
] ]
}, },
"execution_count": 31, "execution_count": 57,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -275,7 +275,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 58,
"id": "1221baee", "id": "1221baee",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -384,7 +384,7 @@
"9 2005.569863 20050728 IRA must hand over criminal assets - McDowell" "9 2005.569863 20050728 IRA must hand over criminal assets - McDowell"
] ]
}, },
"execution_count": 32, "execution_count": 58,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -395,7 +395,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 59,
"id": "58cb7b89", "id": "58cb7b89",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -482,7 +482,7 @@
"9 news" "9 news"
] ]
}, },
"execution_count": 33, "execution_count": 59,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -493,7 +493,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 60,
"id": "cfb113b6", "id": "cfb113b6",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -506,7 +506,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 61,
"id": "046f00be", "id": "046f00be",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -516,7 +516,7 @@
"'Sudan claims it is disarming militias'" "'Sudan claims it is disarming militias'"
] ]
}, },
"execution_count": 35, "execution_count": 61,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -527,7 +527,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 62,
"id": "9d36394d", "id": "9d36394d",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -548,7 +548,7 @@
"Name: 2, Length: 1186898, dtype: object" "Name: 2, Length: 1186898, dtype: object"
] ]
}, },
"execution_count": 36, "execution_count": 62,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -559,7 +559,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 63,
"id": "58d6e666", "id": "58d6e666",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -570,7 +570,7 @@
" 'removed'], dtype=object)" " 'removed'], dtype=object)"
] ]
}, },
"execution_count": 37, "execution_count": 63,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -581,7 +581,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 64,
"id": "86d6f712", "id": "86d6f712",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -594,7 +594,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 65,
"id": "4491cae8", "id": "4491cae8",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -651,7 +651,7 @@
"3 3" "3 3"
] ]
}, },
"execution_count": 39, "execution_count": 65,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -662,7 +662,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 66,
"id": "6eccbc39", "id": "6eccbc39",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -672,7 +672,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 67,
"id": "e09e6a3f", "id": "e09e6a3f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -682,7 +682,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 68,
"id": "f0e4b5fc", "id": "f0e4b5fc",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -692,7 +692,7 @@
"pandas.core.frame.DataFrame" "pandas.core.frame.DataFrame"
] ]
}, },
"execution_count": 42, "execution_count": 68,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -703,7 +703,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 69,
"id": "7662ca93", "id": "7662ca93",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -713,7 +713,7 @@
"pandas.core.series.Series" "pandas.core.series.Series"
] ]
}, },
"execution_count": 43, "execution_count": 69,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -724,7 +724,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 70,
"id": "a1838cd6", "id": "a1838cd6",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -1734,7 +1734,7 @@
" ...]" " ...]"
] ]
}, },
"execution_count": 44, "execution_count": 70,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1745,7 +1745,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": 71,
"id": "3eedae48", "id": "3eedae48",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1756,7 +1756,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 72,
"id": "adc7bcd0", "id": "adc7bcd0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1769,7 +1769,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 73,
"id": "2b9ce936", "id": "2b9ce936",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1781,7 +1781,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 74,
"id": "cef5f0c2", "id": "cef5f0c2",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -1800,7 +1800,7 @@
" '| headline: UK investigation into Icelandic bank fraud abandoned']" " '| headline: UK investigation into Icelandic bank fraud abandoned']"
] ]
}, },
"execution_count": 48, "execution_count": 74,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1811,7 +1811,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 75,
"id": "062f0bd1", "id": "062f0bd1",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -1824,7 +1824,7 @@
" \"| headline: Those who can't\"]" " \"| headline: Those who can't\"]"
] ]
}, },
"execution_count": 49, "execution_count": 75,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1835,7 +1835,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 76,
"id": "f20d5d1d", "id": "f20d5d1d",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1854,7 +1854,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 77,
"id": "4c68c041", "id": "4c68c041",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1864,7 +1864,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 78,
"id": "9da03434", "id": "9da03434",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1874,7 +1874,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": 79,
"id": "f8d5471d", "id": "f8d5471d",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -1885,7 +1885,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "948f6088", "id": "37353752",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []

View File

@ -1,33 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "977d76ed",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

170
keras_class.ipynb Normal file
View File

@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "9e3e0aed",
"metadata": {},
"outputs": [],
"source": [
"from keras.preprocessing.image import ImageDataGenerator\n",
"from keras.models import Sequential\n",
"from keras.layers import Conv2D, MaxPooling2D\n",
"from keras.layers import Activation, Dropout, Flatten, Dense\n",
"from keras import backend as K\n",
" \n",
"img_width, img_height = 224, 224"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "976c0dc7",
"metadata": {},
"outputs": [],
"source": [
"train_data_dir = 'v_data/train'\n",
"validation_data_dir = 'v_data/test'\n",
"nb_train_samples =400\n",
"nb_validation_samples = 100\n",
"epochs = 10\n",
"batch_size = 16"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9bf78481",
"metadata": {},
"outputs": [],
"source": [
"# check format\n",
"\n",
"\n",
"if K.image_data_format() == 'channels_first':\n",
" input_shape = (3, img_width, img_height)\n",
"else:\n",
" input_shape = (img_width, img_height, 3)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a0663374",
"metadata": {},
"outputs": [],
"source": [
"model = Sequential()\n",
"model.add(Conv2D(32, (2, 2), input_shape=input_shape))\n",
"model.add(Activation('relu'))\n",
"model.add(MaxPooling2D(pool_size=(2, 2)))\n",
" \n",
"model.add(Conv2D(32, (2, 2)))\n",
"model.add(Activation('relu'))\n",
"model.add(MaxPooling2D(pool_size=(2, 2)))\n",
" \n",
"model.add(Conv2D(64, (2, 2)))\n",
"model.add(Activation('relu'))\n",
"model.add(MaxPooling2D(pool_size=(2, 2)))\n",
" \n",
"model.add(Flatten())\n",
"model.add(Dense(64))\n",
"model.add(Activation('relu'))\n",
"model.add(Dropout(0.5))\n",
"model.add(Dense(1))\n",
"model.add(Activation('sigmoid'))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6fadd7e5",
"metadata": {},
"outputs": [],
"source": [
"\n",
"model.compile(loss='binary_crossentropy',\n",
" optimizer='rmsprop',\n",
" metrics=['accuracy'])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0bb1a7ba",
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[WinError 3] The system cannot find the path specified: 'v_data/train'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"Input \u001b[1;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 9>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m train_datagen \u001b[38;5;241m=\u001b[39m ImageDataGenerator(\n\u001b[0;32m 2\u001b[0m rescale\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1.\u001b[39m \u001b[38;5;241m/\u001b[39m \u001b[38;5;241m255\u001b[39m,\n\u001b[0;32m 3\u001b[0m shear_range\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.2\u001b[39m,\n\u001b[0;32m 4\u001b[0m zoom_range\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.2\u001b[39m,\n\u001b[0;32m 5\u001b[0m horizontal_flip\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m 7\u001b[0m test_datagen \u001b[38;5;241m=\u001b[39m ImageDataGenerator(rescale\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1.\u001b[39m \u001b[38;5;241m/\u001b[39m \u001b[38;5;241m255\u001b[39m)\n\u001b[1;32m----> 9\u001b[0m train_generator \u001b[38;5;241m=\u001b[39m \u001b[43mtrain_datagen\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mflow_from_directory\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 10\u001b[0m \u001b[43m \u001b[49m\u001b[43mtrain_data_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mtarget_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mimg_width\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mimg_height\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbatch_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 13\u001b[0m \u001b[43m \u001b[49m\u001b[43mclass_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mbinary\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 15\u001b[0m validation_generator \u001b[38;5;241m=\u001b[39m test_datagen\u001b[38;5;241m.\u001b[39mflow_from_directory(\n\u001b[0;32m 16\u001b[0m validation_data_dir,\n\u001b[0;32m 17\u001b[0m target_size\u001b[38;5;241m=\u001b[39m(img_width, img_height),\n\u001b[0;32m 18\u001b[0m batch_size\u001b[38;5;241m=\u001b[39mbatch_size,\n\u001b[0;32m 19\u001b[0m class_mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbinary\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 21\u001b[0m model\u001b[38;5;241m.\u001b[39mfit_generator(\n\u001b[0;32m 22\u001b[0m train_generator,\n\u001b[0;32m 23\u001b[0m steps_per_epoch\u001b[38;5;241m=\u001b[39mnb_train_samples \u001b[38;5;241m/\u001b[39m\u001b[38;5;241m/\u001b[39m batch_size,\n\u001b[0;32m 24\u001b[0m epochs\u001b[38;5;241m=\u001b[39mepochs,\n\u001b[0;32m 25\u001b[0m validation_data\u001b[38;5;241m=\u001b[39mvalidation_generator,\n\u001b[0;32m 26\u001b[0m validation_steps\u001b[38;5;241m=\u001b[39mnb_validation_samples \u001b[38;5;241m/\u001b[39m\u001b[38;5;241m/\u001b[39m batch_size)\n",
"File \u001b[1;32m~\\.conda\\envs\\py\\lib\\site-packages\\keras\\preprocessing\\image.py:1469\u001b[0m, in \u001b[0;36mImageDataGenerator.flow_from_directory\u001b[1;34m(self, directory, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, save_to_dir, save_prefix, save_format, follow_links, subset, interpolation, keep_aspect_ratio)\u001b[0m\n\u001b[0;32m 1386\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mflow_from_directory\u001b[39m(\u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 1387\u001b[0m directory,\n\u001b[0;32m 1388\u001b[0m target_size\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m256\u001b[39m, \u001b[38;5;241m256\u001b[39m),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1400\u001b[0m interpolation\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnearest\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 1401\u001b[0m keep_aspect_ratio\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[0;32m 1402\u001b[0m \u001b[38;5;124;03m\"\"\"Takes the path to a directory & generates batches of augmented data.\u001b[39;00m\n\u001b[0;32m 1403\u001b[0m \n\u001b[0;32m 1404\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1467\u001b[0m \u001b[38;5;124;03m and `y` is a numpy array of corresponding labels.\u001b[39;00m\n\u001b[0;32m 1468\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m-> 1469\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mDirectoryIterator\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1470\u001b[0m \u001b[43m \u001b[49m\u001b[43mdirectory\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1471\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1472\u001b[0m \u001b[43m \u001b[49m\u001b[43mtarget_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtarget_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1473\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcolor_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1474\u001b[0m \u001b[43m \u001b[49m\u001b[43mkeep_aspect_ratio\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkeep_aspect_ratio\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1475\u001b[0m \u001b[43m \u001b[49m\u001b[43mclasses\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclasses\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1476\u001b[0m \u001b[43m \u001b[49m\u001b[43mclass_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclass_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1477\u001b[0m \u001b[43m \u001b[49m\u001b[43mdata_format\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1478\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbatch_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1479\u001b[0m \u001b[43m \u001b[49m\u001b[43mshuffle\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mshuffle\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1480\u001b[0m \u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1481\u001b[0m \u001b[43m \u001b[49m\u001b[43msave_to_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msave_to_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1482\u001b[0m \u001b[43m \u001b[49m\u001b[43msave_prefix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msave_prefix\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1483\u001b[0m \u001b[43m \u001b[49m\u001b[43msave_format\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msave_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1484\u001b[0m \u001b[43m \u001b[49m\u001b[43mfollow_links\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfollow_links\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1485\u001b[0m \u001b[43m \u001b[49m\u001b[43msubset\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msubset\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1486\u001b[0m \u001b[43m \u001b[49m\u001b[43minterpolation\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minterpolation\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1487\u001b[0m \u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdtype\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32m~\\.conda\\envs\\py\\lib\\site-packages\\keras\\preprocessing\\image.py:507\u001b[0m, in \u001b[0;36mDirectoryIterator.__init__\u001b[1;34m(self, directory, image_data_generator, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, data_format, save_to_dir, save_prefix, save_format, follow_links, subset, interpolation, keep_aspect_ratio, dtype)\u001b[0m\n\u001b[0;32m 505\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m classes:\n\u001b[0;32m 506\u001b[0m classes \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m--> 507\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m subdir \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28msorted\u001b[39m(\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlistdir\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdirectory\u001b[49m\u001b[43m)\u001b[49m):\n\u001b[0;32m 508\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39misdir(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(directory, subdir)):\n\u001b[0;32m 509\u001b[0m classes\u001b[38;5;241m.\u001b[39mappend(subdir)\n",
"\u001b[1;31mFileNotFoundError\u001b[0m: [WinError 3] The system cannot find the path specified: 'v_data/train'"
]
}
],
"source": [
"train_datagen = ImageDataGenerator(\n",
" rescale=1. / 255,\n",
" shear_range=0.2,\n",
" zoom_range=0.2,\n",
" horizontal_flip=True)\n",
" \n",
"test_datagen = ImageDataGenerator(rescale=1. / 255)\n",
" \n",
"train_generator = train_datagen.flow_from_directory(\n",
" train_data_dir,\n",
" target_size=(img_width, img_height),\n",
" batch_size=batch_size,\n",
" class_mode='binary')\n",
" \n",
"validation_generator = test_datagen.flow_from_directory(\n",
" validation_data_dir,\n",
" target_size=(img_width, img_height),\n",
" batch_size=batch_size,\n",
" class_mode='binary')\n",
" \n",
"model.fit_generator(\n",
" train_generator,\n",
" steps_per_epoch=nb_train_samples // batch_size,\n",
" epochs=epochs,\n",
" validation_data=validation_generator,\n",
" validation_steps=nb_validation_samples // batch_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "623ec03f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "py",
"language": "python",
"name": "py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}