PetDetectionPy/EndProduct.ipynb
2023-01-05 00:25:12 +01:00

72 lines
1.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "bc93610d",
"metadata": {},
"outputs": [],
"source": [
"# Importieren der Pakekte\n",
"import cv2\n",
"import tensorflow as tf\n",
"\n",
"# Kategorien defienieren. In diesem Falle nur 2 da wir mit einem Binary_Crossentropy arbeiten (Nur 2 Klassifizierungen)\n",
"category = ['Dog', 'Cat'] \n",
"\n",
"# Dateipfad und funktion definieren\n",
"def prepare(filepath):\n",
" \n",
" # Größe des Bildes bestimmen (Desto kleiner desto weniger Lernmaterial) \n",
" IMG_SIZE = 50\n",
" \n",
" # Bild in einen Array machen und in Schwarz-Weiß umformen\n",
" img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)\n",
" \n",
" # Bild größe anpassen\n",
" new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))\n",
" \n",
" # Bild als Schwarz-Weiß und mit neuer Größe zurückgeben\n",
" return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)\n",
"\n",
"#Model das wir bereits erstellt haben, hier reinladen und verwenden (WICHTIG: Name MUSS übereinstimmen)\n",
"model = tf.keras.models.load_model(\"64x3-CNN.model\")\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f07fa08",
"metadata": {},
"outputs": [],
"source": [
"prediction = model.predict([prepare('dog.jpg')])\n",
"print(prediction)"
]
}
],
"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
}