From bd36d57d4727270a377b669b27d77e5df6e2952f Mon Sep 17 00:00:00 2001 From: MGPR23 <darklotenant@gmail.com> Date: Sun, 14 Apr 2024 08:56:16 +0200 Subject: [PATCH] =?UTF-8?q?Warehouse=20-=20Clothing=20=C3=BCbersetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notebook.ipynb | 190 ++++++++++-------- 1 file changed, 101 insertions(+), 89 deletions(-) diff --git a/Warehouse/Classification of clothing through images/notebook.ipynb b/Warehouse/Classification of clothing through images/notebook.ipynb index 2eb9240..45a140a 100644 --- a/Warehouse/Classification of clothing through images/notebook.ipynb +++ b/Warehouse/Classification of clothing through images/notebook.ipynb @@ -11,32 +11,34 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Many online mail order companies have a high return rate\n", - "(of up to 50%), with 97% of all returned products being able to be restocked\n", - "and can be sold. In order to resell the goods\n", - "goods, they must be identified, labeled, and restocked accordingly.\n", - "again.\n", - "Assuming that in 2020 185.5 million orders (Statista, 2021) with\n", - "6 items each (acceptance) would be received, then a return rate of 50% would mean that\n", - "of 50%, 556.5 million items would have to be re-identified and re-categorized.\n", - "To support this process and to facilitate identification of the\n", - "returned garments, image recognition software is to be developed that will\n", - "the associated categories of the individual garments on the basis of images.\n", - "of the individual garments on the basis of images." + "Viele Online-Versandhändler haben eine hohe Rückgabequote\n", + "(bis zu 50 %), wobei 97 % aller zurückgesandten Produkte wieder aufgefüllt werden können\n", + "und verkauft werden können. Um die Waren weiterverkaufen zu können\n", + "müssen die Waren identifiziert, etikettiert und entsprechend wieder aufgestockt werden.\n", + "wieder.\n", + "Geht man davon aus, dass im Jahr 2020 185,5 Millionen Bestellungen (Statista, 2021) mit\n", + "6 Stück (Annahme) eingehen würden, dann würde eine Retourenquote von 50% bedeuten, dass\n", + "Bei einer Rücklaufquote von 50 % müssten 556,5 Millionen Artikel neu identifiziert und kategorisiert werden.\n", + "Zur Unterstützung dieses Prozesses und zur leichteren Identifizierung der\n", + "Kleidungsstücke zu erleichtern, soll eine Bilderkennungssoftware entwickelt werden, die\n", + "die zugehörigen Kategorien der einzelnen Kleidungsstücke auf der Grundlage von Bildern.\n", + "der einzelnen Kleidungsstücke auf der Grundlage von Bildern.\n", + "\n", + "Übersetzt mit DeepL.com (kostenlose Version)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 2. Read Data" + "# 2. Auslesen der Daten" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## 2.1. Import of Relavant Modules " + "## 2.1. Bibliotheken importieren" ] }, { @@ -83,20 +85,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 2.2 Read Data\n" + "## 2.2 Auslesen der Daten\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The training- and test-data is already labeled and split up into two datasets\n", + "Die Trainings- und Testdaten sind bereits beschriftet und in zwei Datensätze aufgeteilt\n", "\n", - "### It is required to download and extract the dataset from:\n", + "### Es ist erforderlich, den Datensatz herunterzuladen und zu extrahieren von:\n", "\n", "https://reutlingenuniversityde-my.sharepoint.com/:f:/g/personal/elias_waschin-scholvin_student_reutlingen-university_de/EnMJgHGtwG5Egw42bRMioMABm5MIJ3ydPJJI36qmse7VpA?e=bRYeWg\n", "\n", - "Please extract to a /data folder" + "Bitte entpacken Sie in einen /data Ordner" ] }, { @@ -134,7 +136,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 2.3. Data Analysis" + "## 2.3. Daten Analyse" ] }, { @@ -350,11 +352,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Describe the dataframe, not really helpful in this case, but is shows that the data is not corrupted by evaluating:\n", - "- Label must be between 0 and 9\n", - "- Pixel values must be between 0 and 255 (non-negative)\n", - "- Count must be 60000 (train) 10000 (test)\n", - "- Maximum number of pixels must be 784 for all rows" + "Beschreiben Sie den Datenrahmen, was in diesem Fall nicht wirklich hilfreich ist, aber es zeigt, dass die Daten nicht durch die Auswertung verfälscht wurden:\n", + "- Die Bezeichnung muss zwischen 0 und 9 liegen.\n", + "- Die Pixelwerte müssen zwischen 0 und 255 liegen (nicht negativ)\n", + "- Die Anzahl muss 60000 (train) 10000 (test) betragen\n", + "- Die maximale Anzahl der Pixel muss 784 für alle Zeilen betragen." ] }, { @@ -981,14 +983,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Both test data and train data seems to be valid and uncorrupted" + "Sowohl die Test- als auch die Trainingsdaten scheinen gültig und unverfälscht zu sein." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Define human readable names for the 10 categories" + "Definieren Sie menschenlesbare Namen für die 10 Kategorien" ] }, { @@ -1005,7 +1007,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Split the dataset an check the distribution of each class (split could be also done later)" + "Aufteilung des Datensatzes und Überprüfung der Verteilung der einzelnen Klassen (die Aufteilung kann auch später erfolgen)" ] }, { @@ -1034,7 +1036,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Show the distribution for each set" + "Zeigen Sie die Verteilung für jeden Satz" ] }, { @@ -1116,8 +1118,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This is already helpful, we can see that it is quite evenly split.\n", - "Print the data as a pie chart, to make it even nicer." + "Das ist bereits hilfreich, denn wir können sehen, dass sie ziemlich gleichmäßig aufgeteilt sind.\n", + "Drucken Sie die Daten als Tortendiagramm aus, um es noch schöner zu machen." ] }, { @@ -1179,7 +1181,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Print a single image" + "Print eines einzelnen Bildes" ] }, { @@ -1221,7 +1223,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Print one image from each category to see how they look like and how they differ" + "Printen eines Bildes aus jeder Kategorie, um zu sehen, wie sie aussehen und wie sie sich unterscheiden" ] }, { @@ -1271,7 +1273,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 3.1. Test and Train Data" + "## 3.1. Daten Testen und Trainieren" ] }, { @@ -1295,7 +1297,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 3.2. Feature Scaling" + "## 3.2. Merkmal Skalierung" ] }, { @@ -1313,7 +1315,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Convert the image shape from 784 to 28x28 (only if load as CSV with 784 columns)" + "Konvertierung der Bildform von 784 in 28x28 (nur wenn als CSV mit 784 Spalten geladen)" ] }, { @@ -1334,7 +1336,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 3.3. Convert Labels" + "## 3.3. Labels Konvertieren" ] }, { @@ -1352,7 +1354,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Check the data shapes to get ensure that the data is in the correct format" + "Überprüfen der Datenformen, um sicherzustellen, dass die Daten im richtigen Format vorliegen." ] }, { @@ -1388,27 +1390,27 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# 4. Modelling and Evaluation" + "# 4. Modellierung und Evaluation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Define how the model will look like. Below some descriptions for different Layer types.\n", - "The first trial of this model was just a DNN with simple dense layers, but the results can be improved by using a CNN.\n", - "As a start architecture the LeNet-5 implementation was chosen and then altered.\n", - "The hyperparameters could also be optimized with a Keras Optimizer which tries out several defined combinations.\n", - "The current parameters got chosen by exploration.\n", + "Definieren Sie, wie das Modell aussehen soll. Nachfolgend finden Sie einige Beschreibungen für verschiedene Schichttypen.\n", + "Der erste Versuch dieses Modells war nur ein DNN mit einfachen dichten Schichten, aber die Ergebnisse können durch die Verwendung eines CNN verbessert werden.\n", + "Als Startarchitektur wurde die LeNet-5-Implementierung gewählt und dann verändert.\n", + "Die Hyperparameter konnten auch mit dem Keras Optimizer optimiert werden, der mehrere definierte Kombinationen ausprobiert.\n", + "Die aktuellen Parameter wurden durch Exploration ausgewählt.\n", "\n", - "- Dense: receives all inputs from previous layer, creates dot product \n", - "- Dropout layer: removes noise for overfitting, drops at specific rate\n", - "- Reshape layer: changes the shape of the input, not used\n", - "- Permute layer: alter shape of the input, not used\n", - "- ReapeatVector layer: repeats the input for fixed number of times, not used\n", - "- Flatten Layer: flattens the matrix\n", - "- MaxPooling2D Layer: reduces number of input\n", - "- Conv2D Layer: convolves an input" + "- Dense: empfängt alle Eingaben aus der vorherigen Schicht und bildet das Punktprodukt \n", + "- Dropout-Schicht: entfernt Rauschen für Overfitting, fällt mit bestimmter Rate ab\n", + "- Reshape-Schicht: verändert die Form der Eingabe, wird nicht verwendet\n", + "- Permute-Schicht: verändert die Form der Eingabe, wird nicht verwendet\n", + "- ReapeatVector-Schicht: wiederholt die Eingabe für eine bestimmte Anzahl von Malen, nicht verwendet\n", + "- Flatten Layer: flacht die Matrix ab\n", + "- MaxPooling2D-Ebene: reduziert die Anzahl der Eingaben\n", + "- Conv2D-Ebene: faltet eine Eingabe zusammen" ] }, { @@ -1461,7 +1463,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Compile the model" + "Kompiliere das Model" ] }, { @@ -1481,7 +1483,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Train/Fit the model" + "Trainiere das Model" ] }, { @@ -1540,7 +1542,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We want do know how especially the loss changes over time" + "Wir wollen wissen, wie sich insbesondere der Verlust im Laufe der Zeit verändert" ] }, { @@ -1596,14 +1598,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can see that the model is performing quite well, but after the second epoch it starts to overfit. To prevent that we could try with different train-validation splits, add more dropout or restructure parts of the model." + "Es ist zu erkennen, dass das Modell recht gut funktioniert, aber nach der zweiten epoche beginnt es zu overfitten. Um dies zu verhindern, könnten wir verschiedene Trainings-Validierungs-Splits ausprobieren, mehr Dropouts hinzufügen oder Teile des Modells umstrukturieren." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Evaluate the test-data" + "Evaluierung der Testdaten" ] }, { @@ -1636,14 +1638,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The model performs quite well with an accuracy of > 90% on the test-data. The loss is acceptable." + "Das Modell schneidet mit einer Genauigkeit von > 90 % bei den Testdaten recht gut ab. Der Verlust ist akzeptabel." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Show results by class" + "Ergebnisse nach Klasse anzeigen" ] }, { @@ -1701,7 +1703,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can observe that the model struggles especially with tops, shirts and pullovers. This is probably due to the fact that they look quite similar. To prevent that it could be helpful to increase image size to get more details, add more color channels or try to identify the texture of the article with some specified layers." + "Wir können beobachten, dass das Modell vor allem mit Oberteilen, Hemden und Pullovern zu kämpfen hat. Das liegt wahrscheinlich daran, dass sie ziemlich ähnlich aussehen. Um dies zu vermeiden, könnte es hilfreich sein, das Bild zu vergrößern, um mehr Details zu erhalten, mehr Farbkanäle hinzuzufügen oder zu versuchen, die Textur des Artikels mit einigen bestimmten Ebenen zu identifizieren." ] }, { @@ -1709,7 +1711,7 @@ "metadata": {}, "source": [ "# 5. Deployment\n", - "Deploy the model as docker container to make it available as a http service" + "Stellen Sie das Modell als Docker-Container bereit, um es als http-Dienst verfügbar zu machen" ] }, { @@ -1733,7 +1735,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Show the data" + "Aufzeigen der Daten" ] }, { @@ -1761,7 +1763,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Zip the model" + "Zippen des Models" ] }, { @@ -1792,27 +1794,37 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Start with the tensorflow/serving docker container if docker is installed\n", + "Starten Sie mit dem Docker-Container tensorflow/serving, wenn Docker installiert ist\n", "```\n", "docker pull tensorflow/serving\n", "docker run -t --rm -p 8501:8501 \\\n", - " -v \"<path_to_model>/fashion_model:/models/fashion_model\" \\\n", + " -v \"<pfad_zum_modell>/fashion_model:/models/fashion_model\" \\\n", " -e MODEL_NAME=fashion_model \\\n", " tensorflow/serving\n", "\n", "```\n", "\n", - "The model should no be available for post requests at http://localhost:8501/v1/models/fashion_model:predict" + "Das Modell sollte nicht für Post-Anfragen unter http://localhost:8501/v1/models/fashion_model:predict verfügbar sein." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Erweiterung 1: Verwendung von RGB-Bildern\n", + "Importieren der allgemeinen RGB-Bilder, die aus dem Internet heruntergeladen wurden, und versuchen, deren Kategorie mit dem Modell vorherzusagen. \n", + "In diesem Fall wurden einige zufällige Bilder von Google heruntergeladen und in eine quadratische Form gebracht.\n", + "Für jede Kategorie befinden sich drei Bilder im \"Custom Set\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Extension 1: Using RGB-Images\n", - "Import general RGB images downloaded from the internet and try to predict their category with the model. \n", - "For this case some random images where downloaded from google, converted to a quadratic shape.\n", - "For each category three images are in the \"custom set\"." + "# Erweiterung 1: Verwendung von RGB-Bildern\n", + "Importieren Sie allgemeine RGB-Bilder, die Sie aus dem Internet heruntergeladen haben, und versuchen Sie, deren Kategorie mit dem Modell vorherzusagen. \n", + "In diesem Fall wurden einige zufällige Bilder von Google heruntergeladen und in eine quadratische Form gebracht.\n", + "Für jede Kategorie befinden sich drei Bilder im \"Custom Set\"." ] }, { @@ -1831,7 +1843,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Load all images by filename (sorted by name)" + "Alle Bilder nach Dateinamen laden (nach Namen sortiert)" ] }, { @@ -1857,7 +1869,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Print all the example images" + "Printen aller Beispiel Bilder" ] }, { @@ -1897,8 +1909,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This is a really important function as it does the actually preprocessing of the image into a format which is \"understandable\" by the model. It probably would make sense to split this function up.\n", - "The commented code below shows how this function could be implemented as custom layer to include it into a model. We subclass a layer for this, but probably we could alternatively just use a \"Lambda\"-Layer (or subclass it)" + "Dies ist eine wirklich wichtige Funktion, da sie die eigentliche Vorverarbeitung des Bildes in ein Format vornimmt, das für das Modell \"verständlich\" ist. Es wäre wahrscheinlich sinnvoll, diese Funktion aufzuteilen.\n", + "Der kommentierte Code unten zeigt, wie diese Funktion als benutzerdefinierte Ebene implementiert werden könnte, um sie in ein Modell einzubinden. Wir subclassen dafür einen Layer, aber wahrscheinlich könnten wir alternativ auch einfach einen \"Lambda\"-Layer verwenden (oder ihn subclassen)" ] }, { @@ -1941,7 +1953,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Show the converted images" + "Anzeigen der konvertierten Bilder" ] }, { @@ -1990,7 +2002,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Predict each image, show the expected result by lable and display the image" + "Jedes Bild vorhersagen, das erwartete Ergebnis durch eine Beschriftung darstellen und das Bild anzeigen" ] }, { @@ -2588,7 +2600,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Create numpy arrays from the loaded data (this could be also done earlier to simplify things)" + "Erstellen von Numpy-Arrays aus den geladenen Daten (dies könnte zur Vereinfachung auch früher geschehen)" ] }, { @@ -2624,7 +2636,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Evaluate our custom-data set" + "Bewerten Sie unseren benutzerdefinierten Datensatz" ] }, { @@ -2709,22 +2721,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The model is performing way worse on the custom-data-set than on the actual test-data. \n", - "This has several reasons and shows how difficult it is to work with \"real\"-data. Although the chosen images are already kind of preprocessed by choosing only image where the article is displayed with a white background, the image is quadratic and the product is shown \"upfront\", there are still a lot of things which make it hard for the model to predict the correct category. Some issues could be:\n", - "- The image should be mirrored (e.g. left shoe/right shoe in the image)\n", - "- The background should be completely white (some images have a shadow)\n", - "- The padding around the article is not the same on all images\n", - "- Rotations can confuse the model (e.g. ankle_boot_2)\n", + "Das Modell schneidet mit dem benutzerdefinierten Datensatz wesentlich schlechter ab als mit den eigentlichen Testdaten. \n", + "Dies hat mehrere Gründe und zeigt, wie schwierig es ist, mit \"echten\" Daten zu arbeiten. Obwohl die ausgewählten Bilder bereits in gewisser Weise vorverarbeitet wurden, indem nur Bilder ausgewählt wurden, bei denen der Artikel mit einem weißen Hintergrund dargestellt wird, das Bild quadratisch ist und das Produkt \"vorne\" gezeigt wird, gibt es immer noch eine Menge Dinge, die es dem Modell schwer machen, die richtige Kategorie vorherzusagen. Einige Probleme könnten sein:\n", + "- Das Bild sollte gespiegelt sein (z. B. linker Schuh/rechter Schuh im Bild)\n", + "- Der Hintergrund sollte komplett weiß sein (einige Bilder haben einen Schatten)\n", + "- Der Rahmen um den Artikel ist nicht bei allen Bildern gleich groß\n", + "- Drehungen können das Modell verwirren (z. B. ankle_boot_2)\n", "\n", - "It is clear that this data is not representative in any way." + "Es ist klar, dass diese Daten in keiner Weise repräsentativ sind." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Extension 2\n", - "Try to visualize the layer output of specific layers." + "# Erweiterung 2\n", + "Versuchen Sie, die Ebenenausgabe bestimmter Ebenen zu visualisieren." ] }, { @@ -2740,7 +2752,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get a sample image from the training-data" + "Abrufen eines Beispielbildes aus den Trainingsdaten" ] }, { @@ -2771,7 +2783,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We iterate over the output of the Layers and display the results for this specific image after the first and the second Convolutional-Layer " + "Wir iterieren über die Ausgabe der Schichten und zeigen die Ergebnisse für dieses spezifische Bild nach der ersten und der zweiten Faltungsschicht an " ] }, { @@ -2829,7 +2841,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now we want to output each filter for the convolutional-layers and the max-pool-layer for the specific image" + "Jetzt wollen wir jeden Filter für die Faltungsschichten und die Max-Pool-Schicht für das jeweilige Bild ausgeben" ] }, { -- GitLab