diff --git a/Combined_Model.ipynb b/Combined_Model.ipynb deleted file mode 100644 index 13f297b..0000000 --- a/Combined_Model.ipynb +++ /dev/null @@ -1,117 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "ZELjx8qt4t3u" - }, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mRunning cells with 'venv (Python 3.13.0)' requires the ipykernel package.\n", - "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n", - "\u001b[1;31mCommand: '\"c:/Users/user/Machine learnin+API/mubazir-machine-learning/venv/Scripts/python.exe\" -m pip install ipykernel -U --force-reinstall'" - ] - } - ], - "source": [ - "#PALING BENER\n", - "\n", - "import os\n", - "import numpy as np\n", - "import tensorflow as tf\n", - "from tensorflow.keras.models import load_model\n", - "from tensorflow.keras.utils import load_img, img_to_array\n", - "import matplotlib.pyplot as plt\n", - "from google.colab import files\n", - "\n", - "# Load model gabungan\n", - "combined_model = load_model('/content/combined_model.h5')\n", - "\n", - "# Daftar class labels untuk model pertama\n", - "class_labels = ['Apel', 'Pisang', 'Paprika', 'Jeruk', 'Wortel', 'Timun']\n", - "\n", - "# Fungsi untuk prediksi jenis buah\n", - "def predict_jenis_buah(model, class_labels, file_name, target_size=(224, 224), confidence_threshold=0.6):\n", - " img = load_img(file_name, target_size=target_size)\n", - " img_array = img_to_array(img)\n", - " img_array = np.expand_dims(img_array, axis=0) / 255.0\n", - " prediction = model.predict([img_array, np.zeros((1, 150, 150, 3))])[0]\n", - " confidence = np.max(prediction)\n", - " print(f\"Predictions: {prediction}, Confidence: {confidence}\") # Debugging output\n", - " predicted_class_index = np.argmax(prediction)\n", - " if predicted_class_index >= len(class_labels) or confidence < confidence_threshold:\n", - " return \"Cannot be predicted\", confidence\n", - " predicted_label = class_labels[predicted_class_index]\n", - " return predicted_label, confidence\n", - "\n", - "# Fungsi untuk prediksi kesegaran buah\n", - "def predict_kesegaran(model, file_name, target_size=(150, 150)):\n", - " img = load_img(file_name, target_size=target_size)\n", - " img_array = img_to_array(img)\n", - " img_array = np.expand_dims(img_array, axis=0) / 255.0\n", - " prediction = model.predict([np.zeros((1, 224, 224, 3)), img_array])[1]\n", - " print(f\"Kesegaran prediction: {prediction}\") # Debugging output\n", - " predicted_label = 'Segar' if prediction[0] > 0.01 else 'Tidak Segar'\n", - " return predicted_label\n", - "\n", - "# Mengunggah dan memprediksi gambar baru\n", - "uploaded = files.upload()\n", - "for fn in uploaded.keys():\n", - " file_path = fn\n", - " jenis_buah, confidence = predict_jenis_buah(combined_model, class_labels, file_path)\n", - " if jenis_buah == \"Cannot be predicted\":\n", - " kesegaran_buah = \"Cannot be predicted\"\n", - " else:\n", - " kesegaran_buah = predict_kesegaran(combined_model, file_path)\n", - "\n", - " # Menampilkan hasil prediksi\n", - " img = load_img(file_path)\n", - " plt.imshow(img)\n", - " plt.title(f'Predicted: {jenis_buah} (Confidence: {confidence:.2f}), Kesegaran: {kesegaran_buah}')\n", - " plt.axis('off')\n", - " plt.show()\n", - "\n", - " print(f'Gambar {fn} adalah {jenis_buah}, dan buah tersebut {kesegaran_buah}')\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mRunning cells with 'venv (Python 3.13.0)' requires the ipykernel package.\n", - "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n", - "\u001b[1;31mCommand: '\"c:/Users/user/Machine learnin+API/mubazir-machine-learning/venv/Scripts/python.exe\" -m pip install ipykernel -U --force-reinstall'" - ] - } - ], - "source": [] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python", - "version": "3.13.0" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -}