Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • ckaufmann/install-python-tensorflow-gym
1 result
Select Git revision
Show changes
Commits on Source (2)
No preview for this file type
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
\usepackage[colorlinks=true,urlcolor=blue,unicode=true,pdfusetitle]{hyperref} \usepackage[colorlinks=true,urlcolor=blue,unicode=true,pdfusetitle]{hyperref}
\usepackage[color=blue, author={Christof Kaufmann}]{attachfile2} % load after hyperref to avoid option clash from unicode=true \usepackage[color=blue, author={Christof Kaufmann}]{attachfile2} % load after hyperref to avoid option clash from unicode=true
\title{Installationsanleitung für Python mit OpenAI Gym für Linux} \title{Installationsanleitung für Python auf Linux}
\date{Oktober 2024} \date{November 2024}
\author{Christof Kaufmann} \author{Christof Kaufmann}
% one infinite page, https://tex.stackexchange.com/a/19241/115883 % one infinite page, https://tex.stackexchange.com/a/19241/115883
...@@ -130,7 +130,7 @@ Wir erstellen nun eine Umgebung namens \lstinline|ml| mit Python 3.10 und den be ...@@ -130,7 +130,7 @@ Wir erstellen nun eine Umgebung namens \lstinline|ml| mit Python 3.10 und den be
matplotlib seaborn scikit-learn openpyxl odfpy pyarrow \ matplotlib seaborn scikit-learn openpyxl odfpy pyarrow \
geopandas descartes 'pyogrio<0.8.0' optuna plotly tqdm \ geopandas descartes 'pyogrio<0.8.0' optuna plotly tqdm \
jax-jumpy moviepy shimmy-atari gymnasium-box2d spyder \ jax-jumpy moviepy shimmy-atari gymnasium-box2d spyder \
ipywidgets notebook lxml fastparquet zstandard \ ipywidgets notebook lxml fastparquet zstandard gradio \
contextily networkx pyvis netgraph pip contextily networkx pyvis netgraph pip
\end{lstlisting} \end{lstlisting}
......
No preview for this file type
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
\usepackage[color=blue, author={Christof Kaufmann}]{attachfile2} % load after hyperref to avoid option clash from unicode=true \usepackage[color=blue, author={Christof Kaufmann}]{attachfile2} % load after hyperref to avoid option clash from unicode=true
\title{Installationsanleitung für Python mit OpenAI Gym für Windows} \title{Installationsanleitung für Python auf Windows}
\date{Oktober 2024} \date{November 2024}
\author{Christof Kaufmann} \author{Christof Kaufmann}
...@@ -130,9 +130,9 @@ Wir erstellen nun eine Umgebung namens \lstinline|ml| mit Python 3.10 und den be ...@@ -130,9 +130,9 @@ Wir erstellen nun eine Umgebung namens \lstinline|ml| mit Python 3.10 und den be
\begin{lstlisting}[gobble=2, basicstyle=\ttfamily\footnotesize] \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\footnotesize]
mamba create -n ml python=3.10 seaborn plotly matplotlib ipympl ipywidgets ^ mamba create -n ml python=3.10 seaborn plotly matplotlib ipympl ipywidgets ^
scikit-learn optuna astunparse git jupyter notebook spyder ^ scikit-learn optuna astunparse git jupyter notebook spyder ^
openpyxl odfpy lxml pyarrow fastparquet zstandard mypy ^ openpyxl odfpy lxml pyarrow fastparquet zstandard mypy pip ^
geopandas "pyogrio<0.8.0" contextily networkx netgraph ^ geopandas "pyogrio<0.8.0" contextily networkx netgraph ^
pyvis jax-jumpy moviepy shimmy-atari gymnasium-box2d pip pyvis jax-jumpy moviepy shimmy-atari gymnasium-box2d gradio
\end{lstlisting} \end{lstlisting}
Sie können die Umgebung jederzeit mit \lstinline|mamba activate ml| aktivieren und mit \lstinline|mamba deactivate| deaktivieren. Generell können Sie auch weitere Umgebungen mit \lstinline|mamba create -n <MYENVNAME> <PAKETE>| einrichten und diese mit \lstinline|mamba activate <MYENVNAME>| aktivieren. Sie können die Umgebung jederzeit mit \lstinline|mamba activate ml| aktivieren und mit \lstinline|mamba deactivate| deaktivieren. Generell können Sie auch weitere Umgebungen mit \lstinline|mamba create -n <MYENVNAME> <PAKETE>| einrichten und diese mit \lstinline|mamba activate <MYENVNAME>| aktivieren.
......
import tensorflow as tf import tensorflow as tf
import keras import keras
from keras.models import Sequential from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Input
from keras.utils import to_categorical from keras.utils import to_categorical
from keras.datasets import mnist from keras.datasets import mnist
...@@ -9,35 +9,38 @@ print('=========================') ...@@ -9,35 +9,38 @@ print('=========================')
print('TensorFlow Version', tf.__version__) print('TensorFlow Version', tf.__version__)
print('Keras Version ', keras.__version__) print('Keras Version ', keras.__version__)
print('=========================') print('=========================')
print(tf.config.list_physical_devices())
print('=========================')
(XTrain, yTrain), (XTest, yTest) = mnist.load_data() (X_train, y_train), (X_test, y_test) = mnist.load_data()
XTrain = XTrain.reshape(60000, 28, 28, 1) X_train = X_train.reshape(60000, 28, 28, 1)
XTest = XTest.reshape(10000, 28, 28, 1) X_test = X_test.reshape(10000, 28, 28, 1)
XTrain = XTrain / 255 X_train = X_train / 255
XTest = XTest / 255 X_test = X_test / 255
YTrain = to_categorical(yTrain, 10) y_train = to_categorical(y_train, 10)
YTest = to_categorical(yTest, 10) y_test = to_categorical(y_test, 10)
myANN = Sequential() model = Sequential()
myANN.add(Conv2D(9, kernel_size=(3, 3), activation='relu', kernel_initializer='he_uniform', input_shape=(28, 28, 1))) myANN.add(Input((28, 28, 1)))
myANN.add(MaxPooling2D(2)) model.add(Conv2D(9, kernel_size=(3, 3), activation='relu', kernel_initializer='he_uniform'))
myANN.add(Flatten()) model.add(MaxPooling2D(2))
myANN.add(Dense(20, activation='tanh')) model.add(Flatten())
myANN.add(Dense(10, activation='softmax')) model.add(Dense(20, activation='tanh'))
myANN.compile(loss='categorical_crossentropy', optimizer='nadam', metrics=['accuracy']) model.add(Dense(10, activation='softmax'))
myANN.fit(XTrain, YTrain, batch_size=500, epochs=5, verbose=True) model.compile(loss='categorical_crossentropy', optimizer='nadam', metrics=['accuracy'])
model.fit(X_train, y_train, batch_size=500, epochs=5, verbose=True)
mse, acc = myANN.evaluate(XTest, YTest, verbose=False) mse, acc = model.evaluate(X_test, y_test, verbose=False)
print('Test loss:', mse, 'Test accuracy:', acc) print('Test loss:', mse, 'Test accuracy:', acc)
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
fig = plt.figure() fig = plt.figure()
for i in range(9): for i in range(9):
ax = fig.add_subplot(3, 3, i + 1) ax = fig.add_subplot(3, 3, i + 1)
ax.imshow(XTrain[i].squeeze(), cmap='gray', interpolation='none') ax.imshow(X_train[i].squeeze(), cmap='gray', interpolation='none')
ax.set_title(yTrain[i]) ax.set_title(y_train[i])
plt.tight_layout() plt.tight_layout()
plt.show() plt.show()
......