mirror of
https://github.com/VitaAetaerna/PetDetectionPy.git
synced 2024-11-12 22:01:36 +01:00
349 lines
283 KiB
Plaintext
349 lines
283 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"id": "50cc3f9e",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiUAAAGiCAYAAAA4MLYWAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9SYxk2XUe/L2IyJjHjMh5qKyhq7t6YDebpDkYNCnbkk1BsmVtDBsQvJRAwIBAGIYFbUiDoGAtZC0kGxBgwLINwV7ZC0O/bEqWxFEcmmSzh6ruyqrKqTIjM2OeIzIy4l8kvlMnTt0XmdVsmio6L5DIiBfv3ende853xuuNx+MxLstluSyX5bJclstyWX7CJfCT7sBluSyX5bJclstyWS4LcAlKLstluSyX5bJclsvy16RcgpLLclkuy2W5LJflsvy1KJeg5LJclstyWS7LZbksfy3KJSi5LJflslyWy3JZLstfi3IJSi7LZbksl+WyXJbL8teiXIKSy3JZLstluSyX5bL8tSiXoOSyXJbLclkuy2W5LH8tyiUouSyX5bJclstyWS7LX4tyCUouy2W5LJflslyWy/LXovxEQcm/+3f/DlevXkU0GsWHPvQhfPWrX/1JdueyXJbLclkuy2W5LD/B8hMDJf/tv/03/Pqv/zp+8zd/E9///vfxyU9+Ep/5zGews7Pzk+rSZbksl+WyXJbLcll+gsX7SR3I99GPfhSvvvoq/v2///dy7datW/ilX/ol/NZv/dZPokuX5bJclstyWS7LZfkJltBPotHBYIDXXnsN/+pf/auJ6z/3cz+Hb3zjG4/d3+/30e/35ftoNEKlUkE+n4fneT/2/l6Wy3JZLstluSyX5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"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import os\n",
|
||
|
"import numpy as np\n",
|
||
|
"import cv2\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"from tqdm import tqdm\n",
|
||
|
"\n",
|
||
|
"# Directory to Pictures\n",
|
||
|
"DATA_DIR = \"C:/Users/muhle/Desktop/Code/DataSets/PetAI\"\n",
|
||
|
"# Kategorien die zu erkennen sind\n",
|
||
|
"CATEGORIES = [\"DOG\", \"CAT\"]\n",
|
||
|
"\n",
|
||
|
"# Die Ordner mit den Kategorien im Namen Suchen, anschließend alle Bilder in Schwarz-Weiß umformen \n",
|
||
|
"for category in CATEGORIES:\n",
|
||
|
" path = os.path.join(DATA_DIR, category)\n",
|
||
|
" for img in os.listdir(path):\n",
|
||
|
" img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)\n",
|
||
|
" # Anzeigen eines Bildes mit Matplotlib\n",
|
||
|
" plt.imshow(img_array, cmap=\"gray\")\n",
|
||
|
" plt.show()\n",
|
||
|
" break\n",
|
||
|
" break"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"id": "7847ac85",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGfCAYAAAD22G0fAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA6oklEQVR4nO3de3TV1Z3//3dACIGEkHBJuIR7BARFLoogioowxUux6qyOOo51ZnWqqIWy5qsiXqAXUGwpKpYW61LXopSZUVSmihIvBC2iAaEgiCMSSLiEcAlJSEK4fX5/+CPD5ezXJif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W1HYOZ2SeffOKMqb6anTt3ynnVufD1GD300EPO2LvvvuuM+fqp1H350UcfybFjx451xjZs2OCM9e/fX86r+oiKiork2LS0NGdM3VuFhYVyXnVv+a6nzp07O2PqudZlGxTf+5Pr/db3Pn3c45/yTwIAcJqRhAAAwZCEAADBkIQAAMGQhAAAwZCEAADB1LpEe8mSJfb000/bihUrbPv27fb666/bTTfdVBOPosgmT55ss2fPtpKSEhs0aJA9//zz1rt371o9zpEjR2KWaPvKh5977jlnzLccvVpmXZU012XbBF/psZpbPR/fc1Xz+krOfcfs4iv3VK9tSUmJHKvKZrt27eqMVVVVyXnfeustZ+yGG26QY1V5vbJx40YZV+XDatsKM11qrcrVDxw4IOddv369M+Z77dQxvfbaa86YbxuUCy+80BnzbQORkpLijKlS6ksvvVTO+9lnnzljvnOs7mn1fHzPdd++fc6Y7153bfXg2wLiWLX+JFRRUWF
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Größe des Bildes definieren\n",
|
||
|
"IMG_SIZE = 50\n",
|
||
|
"# Größe des Bild Array's ändern\n",
|
||
|
"new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))\n",
|
||
|
"# Neues verpixeltes Bild anzeigen\n",
|
||
|
"plt.imshow(new_array, cmap = 'gray')\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"id": "709419fa",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"100%|██████████| 12501/12501 [01:18<00:00, 159.58it/s]\n",
|
||
|
"100%|██████████| 12501/12501 [01:16<00:00, 163.02it/s]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Liste für Trainingsdaten definieren\n",
|
||
|
"training_data = []\n",
|
||
|
"\n",
|
||
|
"def create_training_data():\n",
|
||
|
" for category in CATEGORIES: # do dogs and cats\n",
|
||
|
"\n",
|
||
|
" path = os.path.join(DATA_DIR,category) # Pfad zu Hunde und Katzen erstellen\n",
|
||
|
" class_num = CATEGORIES.index(category) # Klassifikation für Hund und Katze bekommen, Hund=0; Katze=1;\n",
|
||
|
"\n",
|
||
|
" for img in tqdm(os.listdir(path)): # Bilder von Katzen und Hunden wiederholen\n",
|
||
|
" try:\n",
|
||
|
" img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) # Bild zu einen Array\n",
|
||
|
" new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) # Größe zu einer normalen Datengröße machen (50,50)\n",
|
||
|
" training_data.append([new_array, class_num]) # Hinzufügen zu unserer Liste trainings_data\n",
|
||
|
" except Exception as e: # Wenn ein Fehler auftritt soll es einfach übersrpingen und weitermachen\n",
|
||
|
" pass\n",
|
||
|
"create_training_data()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"id": "41c1245c",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"IOPub data rate exceeded.\n",
|
||
|
"The notebook server will temporarily stop sending output\n",
|
||
|
"to the client in order to avoid crashing it.\n",
|
||
|
"To change this limit, set the config variable\n",
|
||
|
"`--NotebookApp.iopub_data_rate_limit`.\n",
|
||
|
"\n",
|
||
|
"Current values:\n",
|
||
|
"NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
|
||
|
"NotebookApp.rate_limit_window=3.0 (secs)\n",
|
||
|
"\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Länge der training_data\n",
|
||
|
"print(len(training_data))\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"id": "cdfe3e93",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import random\n",
|
||
|
"# Random Werte aus training_data nehmen\n",
|
||
|
"random.shuffle(training_data)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"id": "f1e9c8e5",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"0\n",
|
||
|
"0\n",
|
||
|
"1\n",
|
||
|
"0\n",
|
||
|
"0\n",
|
||
|
"1\n",
|
||
|
"0\n",
|
||
|
"0\n",
|
||
|
"1\n",
|
||
|
"1\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Array ausgeben\n",
|
||
|
"for sample in training_data[:10]:\n",
|
||
|
" print(sample[1])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"id": "5eaae186",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#Input (X) und Output (y) definieren\n",
|
||
|
"X = []\n",
|
||
|
"y = []\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"id": "510602f8",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"\n",
|
||
|
"for features, label in training_data: \n",
|
||
|
" X.append(features)\n",
|
||
|
" y.append(label)\n",
|
||
|
" \n",
|
||
|
"# X in einen Numpy Array umwandeln und ihn eine neue Größe geben, 1 Farmkanal (Grau)\n",
|
||
|
"X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"id": "b59339a3",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import pickle\n",
|
||
|
"# X und y in Pickle dateien schreiben\n",
|
||
|
"pickle_out = open(\"X.pickle\", \"wb\")\n",
|
||
|
"pickle.dump(X, pickle_out)\n",
|
||
|
"pickle_out.close()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"id": "1b487159",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"pickle_out = open(\"y.pickle\", \"wb\")\n",
|
||
|
"pickle.dump(y, pickle_out)\n",
|
||
|
"pickle_out.close()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"id": "6aabb96e",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"pickle_out = open(\"X.pickle\", \"wb\")\n",
|
||
|
"pickle.dump(X, pickle_out)\n",
|
||
|
"pickle_out.close()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"id": "0f0e4ca0",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[[102],\n",
|
||
|
" [139],\n",
|
||
|
" [155],\n",
|
||
|
" ...,\n",
|
||
|
" [113],\n",
|
||
|
" [ 98],\n",
|
||
|
" [ 32]],\n",
|
||
|
"\n",
|
||
|
" [[108],\n",
|
||
|
" [146],\n",
|
||
|
" [160],\n",
|
||
|
" ...,\n",
|
||
|
" [114],\n",
|
||
|
" [ 90],\n",
|
||
|
" [ 16]],\n",
|
||
|
"\n",
|
||
|
" [[116],\n",
|
||
|
" [148],\n",
|
||
|
" [161],\n",
|
||
|
" ...,\n",
|
||
|
" [ 92],\n",
|
||
|
" [ 14],\n",
|
||
|
" [ 13]],\n",
|
||
|
"\n",
|
||
|
" ...,\n",
|
||
|
"\n",
|
||
|
" [[ 99],\n",
|
||
|
" [ 97],\n",
|
||
|
" [105],\n",
|
||
|
" ...,\n",
|
||
|
" [ 77],\n",
|
||
|
" [ 75],\n",
|
||
|
" [ 71]],\n",
|
||
|
"\n",
|
||
|
" [[102],\n",
|
||
|
" [108],\n",
|
||
|
" [103],\n",
|
||
|
" ...,\n",
|
||
|
" [ 76],\n",
|
||
|
" [ 70],\n",
|
||
|
" [ 73]],\n",
|
||
|
"\n",
|
||
|
" [[107],\n",
|
||
|
" [102],\n",
|
||
|
" [110],\n",
|
||
|
" ...,\n",
|
||
|
" [ 86],\n",
|
||
|
" [ 74],\n",
|
||
|
" [ 80]]], dtype=uint8)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"X[1]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "e7532702",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "3ff3800d",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"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.9.15"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|