1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
05a4b1be76 complete Lab24 2024-03-21 00:01:35 +02:00
4021991ec3 move lab1 to subfolder 2024-03-19 23:58:38 +02:00
21 changed files with 72784 additions and 0 deletions

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 15,
"id": "ab7d7dbd-f2e0-4384-8c55-d4aeee74dd7c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The tensorboard extension is already loaded. To reload it, use:\n",
" %reload_ext tensorboard\n",
"WARNING:tensorflow:5 out of the last 5 calls to <function Model.make_predict_function.<locals>.predict_function at 0x7fe3e8248550> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n",
"1/1 [==============================] - 0s 33ms/step\n",
"[[0.03452728]\n",
" [0.9867295 ]\n",
" [0.9883936 ]\n",
" [0.01205833]]\n"
]
},
{
"data": {
"text/plain": [
"Reusing TensorBoard on port 6008 (pid 911540), started 0:22:54 ago. (Use '!kill 911540' to kill it.)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <iframe id=\"tensorboard-frame-e941beefef1b33a0\" width=\"100%\" height=\"800\" frameborder=\"0\">\n",
" </iframe>\n",
" <script>\n",
" (function() {\n",
" const frame = document.getElementById(\"tensorboard-frame-e941beefef1b33a0\");\n",
" const url = new URL(\"/\", window.location);\n",
" const port = 6008;\n",
" if (port) {\n",
" url.port = port;\n",
" }\n",
" frame.src = url;\n",
" })();\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%load_ext tensorboard\n",
"\n",
"import tensorflow as tf\n",
"import numpy as np \n",
"import datetime, os\n",
"\n",
"tf.config.experimental.set_visible_devices([], \"GPU\") \n",
"\n",
"X = np.array([[0,0],[0,1],[1,0],[1,1]])\n",
"y = np.array([[0],[1],[1],[0]])\n",
" \n",
"model = tf.keras.models.Sequential([\n",
" tf.keras.layers.Dense(8, activation='relu', name='layers_dense_1'),\n",
" tf.keras.layers.Dense(8, activation='relu', name='layers_dense_2'),\n",
" tf.keras.layers.Dense(1, activation='sigmoid', name='layers_dense_3')\n",
"])\n",
" \n",
"loss_fn = tf.keras.losses.binary_crossentropy\n",
"\n",
"simple = True\n",
"\n",
"if simple == True:\n",
" model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])\n",
" \n",
" logdir = os.path.join(\"logs\", datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\"))\n",
" tensorboard_callback = tf.keras.callbacks.TensorBoard(logdir, histogram_freq=1)\n",
" model.fit(X, y, batch_size=4, epochs=1000, verbose=0, callbacks = [tensorboard_callback])\n",
"else:\n",
" for i in range(100):\n",
" with tf.GradientTape() as tape:\n",
" # Forward pass.\n",
" predictions = model(X)\n",
" # Compute the loss value for this batch.\n",
" loss_value = loss_fn(y, predictions)\n",
"\n",
" # Get gradients of loss wrt the weights.\n",
" gradients = tape.gradient(loss_value, model.trainable_weights)\n",
" # Update the weights of the model.\n",
" optimizer.apply_gradients(zip(gradients, model.trainable_weights))\n",
"\n",
"print(model.predict(X))\n",
"\n",
"%tensorboard --logdir logs"
]
}
],
"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.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,30 @@
5.9,3,4.2,1.5,1
6.9,3.1,5.4,2.1,2
5.1,3.3,1.7,0.5,0
6,3.4,4.5,1.6,1
5.5,2.5,4,1.3,1
6.2,2.9,4.3,1.3,1
5.5,4.2,1.4,0.2,0
6.3,2.8,5.1,1.5,2
5.6,3,4.1,1.3,1
6.7,2.5,5.8,1.8,2
7.1,3,5.9,2.1,2
4.3,3,1.1,0.1,0
5.6,2.8,4.9,2,2
5.5,2.3,4,1.3,1
6,2.2,4,1,1
5.1,3.5,1.4,0.2,0
5.7,2.6,3.5,1,1
4.8,3.4,1.9,0.2,0
5.1,3.4,1.5,0.2,0
5.7,2.5,5,2,2
5.4,3.4,1.7,0.2,0
5.6,3,4.5,1.5,1
6.3,2.9,5.6,1.8,2
6.3,2.5,4.9,1.5,1
5.8,2.7,3.9,1.2,1
6.1,3,4.6,1.4,1
5.2,4.1,1.5,0.1,0
6.7,3.1,4.7,1.5,1
6.7,3.3,5.7,2.5,2
6.4,2.9,4.3,1.3,1
1 5.9 3 4.2 1.5 1
2 6.9 3.1 5.4 2.1 2
3 5.1 3.3 1.7 0.5 0
4 6 3.4 4.5 1.6 1
5 5.5 2.5 4 1.3 1
6 6.2 2.9 4.3 1.3 1
7 5.5 4.2 1.4 0.2 0
8 6.3 2.8 5.1 1.5 2
9 5.6 3 4.1 1.3 1
10 6.7 2.5 5.8 1.8 2
11 7.1 3 5.9 2.1 2
12 4.3 3 1.1 0.1 0
13 5.6 2.8 4.9 2 2
14 5.5 2.3 4 1.3 1
15 6 2.2 4 1 1
16 5.1 3.5 1.4 0.2 0
17 5.7 2.6 3.5 1 1
18 4.8 3.4 1.9 0.2 0
19 5.1 3.4 1.5 0.2 0
20 5.7 2.5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 1.4 0.3 0
97 4.6 3.2 1.4 0.2 0
98 7.7 2.8 6.7 2 2
99 5.9 3.2 4.8 1.8 1
100 5.1 3.8 1.6 0.2 0
101 4.9 3 1.4 0.2 0
102 4.9 2.4 3.3 1 1
103 4.5 2.3 1.3 0.3 0
104 5.8 2.7 4.1 1 1
105 5 3.4 1.6 0.4 0
106 5.2 3.4 1.4 0.2 0
107 5.3 3.7 1.5 0.2 0
108 5 3.6 1.4 0.2 0
109 5.6 2.9 3.6 1.3 1
110 4.8 3.1 1.6 0.2 0
111 6.3 2.7 4.9 1.8 2
112 5.7 2.8 4.1 1.3 1
113 5 3 1.6 0.2 0
114 6.3 3.3 6 2.5 2
115 5 3.5 1.6 0.6 0
116 5.5 2.6 4.4 1.2 1
117 5.7 3 4.2 1.2 1
118 4.4 2.9 1.4 0.2 0
119 4.8 3 1.4 0.1 0
120 5.5 2.4 3.7 1 1

1433
Lab2/main.ipynb Normal file

File diff suppressed because one or more lines are too long