{ "cells": [ { "cell_type": "code", "execution_count": 5, "id": "7eea0d4d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Num GPUs Available: 2\n" ] } ], "source": [ "import tensorflow as tf\n", "print(\"Num GPUs Available: \", len(tf.config.list_physical_devices('GPU')))\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "33d18ebd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 Physical GPU, 3 Logical GPUs\n" ] } ], "source": [ "gpus = tf.config.list_physical_devices('GPU')\n", "if gpus:\n", " # Create 2 virtual GPUs with 1GB memory each\n", " try:\n", " tf.config.set_logical_device_configuration(\n", " gpus[0],\n", " [tf.config.LogicalDeviceConfiguration(memory_limit=1024),\n", " tf.config.LogicalDeviceConfiguration(memory_limit=1024)])\n", " logical_gpus = tf.config.list_logical_devices('GPU')\n", " print(len(gpus), \"Physical GPU,\", len(logical_gpus), \"Logical GPUs\")\n", " except RuntimeError as e:\n", " # Virtual devices must be set before GPUs have been initialized\n", " print(e)\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "2b9ca96e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "tf.Tensor(\n", "[[22. 28.]\n", " [49. 64.]], shape=(2, 2), dtype=float32)\n" ] } ], "source": [ "tf.debugging.set_log_device_placement(True)\n", "\n", "a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])\n", "b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])\n", "\n", "# Run on the GPU\n", "c = tf.matmul(a, b)\n", "print(c)\n", "\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from keras.models import load_model\n", "\n", "# returns a compiled model\n", "# identical to the previous one\n", "model = load_model('Model_1.h5')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model.predict_generator()" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 5 }