====== Influye el hardware en el resultado ======
Vamos a comprobar si usar distinto hardware influye en el resultado del entrenamiento.
#!/usr/bin/env python3
import sys
import random
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from sklearn.datasets import load_iris
print("Versión de Python:", sys.version)
print("Versión de NumPy:", np.__version__)
print("Versión de TensorFlow:", tf.__version__)
iris=load_iris()
x=iris.data[0:99,[0,2]]
y=iris.target[0:99]
random.seed(5)
np.random.seed(5)
tf.random.set_seed(5)
model=Sequential()
model.add(Dense(5, activation='relu',input_dim=2))
model.add(Dense(5, activation='relu'))
model.compile(loss='mean_squared_error')
model.fit(x, y,epochs=200,verbose=False)
for layer in model.layers:
print(layer.get_weights()[0].reshape(-1))
for layer in model.layers:
print(layer.get_weights()[1])
===== Tensorflow 2.12 =====
* Mi ordenador con Tensorflow 2.12
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.12.0
[ 0.13083223 0.07442822 -0.2500074 0.47630367 0.5291078 0.31813693
0.31183484 0.1446724 -0.7333437 0.18374144]
[ 0.6093438 0.08665708 0.31081778 0.2551267 0.05519938 0.4367431
-0.7268674 0.50311357 -0.63850987 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922246 -0.9340179 -0.15385167
-0.81791097 -0.13371903 -0.1941066 0.5657561 0.03889008 0.4567909
-0.45787498]
[-0.2992502 -0.37618196 0. -0.07332841 -0.29489776]
[ 0.00671715 -0.19779032 -0.40140766 -0.22690465 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197894 1.0331607 1.2148745 1.0691222 0. ]]
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.12.0
[ 0.13083223 0.07442822 -0.2500074 0.47630367 0.5291078 0.31813693
0.31183484 0.1446724 -0.7333437 0.18374144]
[ 0.6093438 0.08665708 0.31081778 0.2551267 0.05519938 0.4367431
-0.7268674 0.50311357 -0.63850987 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922246 -0.9340179 -0.15385167
-0.81791097 -0.13371903 -0.1941066 0.5657561 0.03889008 0.4567909
-0.45787498]
[-0.2992502 -0.37618196 0. -0.07332841 -0.29489776]
[ 0.00671715 -0.19779032 -0.40140766 -0.22690465 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197894 1.0331607 1.2148745 1.0691222 0. ]]
* Google Colab con TPU y tensorflow 2.12
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.12.0
[ 0.13083223 0.07442828 -0.2500074 0.4763036 0.5291076 0.31813705
0.3118346 0.1446724 -0.7333438 0.18374145]
[ 0.60934395 0.08665702 0.3108179 0.25512677 0.05519938 0.43674305
-0.72686714 0.5031137 -0.6385101 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922271 -0.9340177 -0.15385169
-0.8179109 -0.13371903 -0.19410674 0.56575596 0.03888999 0.45679092
-0.45787498]
[-0.29925007 -0.37618205 0. -0.07332825 -0.29489756]
[ 0.00671728 -0.19779012 -0.4014075 -0.22690472 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197894 1.0331607 1.2148745 1.069122 0. ]]
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.12.0
[ 0.13083223 0.07442828 -0.2500074 0.4763036 0.5291076 0.31813705
0.3118346 0.1446724 -0.7333438 0.18374145]
[ 0.60934395 0.08665702 0.3108179 0.25512677 0.05519938 0.43674305
-0.72686714 0.5031137 -0.6385101 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922271 -0.9340177 -0.15385169
-0.8179109 -0.13371903 -0.19410674 0.56575596 0.03888999 0.45679092
-0.45787498]
[-0.29925007 -0.37618205 0. -0.07332825 -0.29489756]
[ 0.00671728 -0.19779012 -0.4014075 -0.22690472 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197894 1.0331607 1.2148745 1.069122 0. ]]
===== Tensorflow 2.14 =====
* Mi ordenador con Tensorflow 2.14
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.26.1
Versión de TensorFlow: 2.14.0
[ 0.13083228 0.07442826 -0.2500074 0.47630364 0.5291078 0.31813696
0.31183475 0.1446724 -0.7333436 0.18374133]
[ 0.6093438 0.08665705 0.31081787 0.25512666 0.05519938 0.43674314
-0.7268673 0.5031135 -0.6385097 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922258 -0.9340178 -0.15385169
-0.8179109 -0.13371903 -0.19410668 0.5657561 0.03889009 0.4567909
-0.45787498]
[-0.29925022 -0.37618196 0. -0.07332844 -0.2948976 ]
[ 0.00671723 -0.19779022 -0.40140778 -0.22690488 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197893 1.0331608 1.2148747 1.0691222 0. ]]
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.26.1
Versión de TensorFlow: 2.14.0
[ 0.13083228 0.07442826 -0.2500074 0.47630364 0.5291078 0.31813696
0.31183475 0.1446724 -0.7333436 0.18374133]
[ 0.6093438 0.08665705 0.31081787 0.25512666 0.05519938 0.43674314
-0.7268673 0.5031135 -0.6385097 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922258 -0.9340178 -0.15385169
-0.8179109 -0.13371903 -0.19410668 0.5657561 0.03889009 0.4567909
-0.45787498]
[-0.29925022 -0.37618196 0. -0.07332844 -0.2948976 ]
[ 0.00671723 -0.19779022 -0.40140778 -0.22690488 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197893 1.0331608 1.2148747 1.0691222 0. ]]
* Google Colab con CPU y tensorflow 2.14
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.14.0
[ 0.13083225 0.07442821 -0.2500074 0.47630358 0.5291077 0.31813702
0.3118347 0.1446724 -0.73334354 0.18374158]
[ 0.609344 0.08665705 0.31081787 0.25512683 0.05519938 0.43674326
-0.72686714 0.5031137 -0.6385102 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922249 -0.93401766 -0.1538516
-0.81791097 -0.13371903 -0.19410674 0.5657558 0.03889002 0.45679078
-0.45787498]
[-0.2992501 -0.37618205 0. -0.07332838 -0.29489738]
[ 0.00671722 -0.1977903 -0.40140763 -0.22690481 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197893 1.033161 1.2148744 1.0691221 0. ]]
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.14.0
[ 0.13083225 0.07442821 -0.2500074 0.47630358 0.5291077 0.31813702
0.3118347 0.1446724 -0.73334354 0.18374158]
[ 0.609344 0.08665705 0.31081787 0.25512683 0.05519938 0.43674326
-0.72686714 0.5031137 -0.6385102 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922249 -0.93401766 -0.1538516
-0.81791097 -0.13371903 -0.19410674 0.5657558 0.03889002 0.45679078
-0.45787498]
[-0.2992501 -0.37618205 0. -0.07332838 -0.29489738]
[ 0.00671722 -0.1977903 -0.40140763 -0.22690481 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197893 1.033161 1.2148744 1.0691221 0. ]]
* Google Colab con T4 GPU y tensorflow 2.14
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.14.0
[ 0.13083227 0.07442828 -0.2500074 0.4763036 0.5291076 0.318137
0.3118347 0.1446724 -0.7333437 0.18374152]
[ 0.60934377 0.08665707 0.31081787 0.2551268 0.05519938 0.4367433
-0.7268671 0.5031135 -0.6385101 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922267 -0.9340178 -0.15385167
-0.817911 -0.13371903 -0.19410676 0.56575596 0.03889004 0.4567909
-0.45787498]
[-0.29925022 -0.37618205 0. -0.07332834 -0.29489756]
[ 0.00671724 -0.19779004 -0.4014077 -0.22690451 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197891 1.033161 1.2148743 1.0691222 0. ]]
Versión de Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Versión de NumPy: 1.23.5
Versión de TensorFlow: 2.14.0
[ 0.13083221 0.07442825 -0.2500074 0.47630355 0.5291077 0.31813705
0.31183478 0.1446724 -0.7333435 0.1837415 ]
[ 0.6093438 0.08665702 0.31081784 0.2551268 0.05519938 0.43674314
-0.726867 0.50311357 -0.63851 0.34656572 0.5320357 -0.48540664
-0.5437882 0.58495295 0.42670572 -0.24922241 -0.9340177 -0.15385164
-0.8179108 -0.13371903 -0.1941067 0.565756 0.03889004 0.45679086
-0.45787498]
[-0.29925022 -0.37618196 0. -0.07332844 -0.29489744]
[ 0.00671725 -0.19779035 -0.40140772 -0.22690469 0. ]
Predict: [[0. 0. 0. 0. 0. ]
[1.2197894 1.0331609 1.2148745 1.0691221 0. ]]
===== Conclusión =====
Los pesos de las redes son similares aunque cambian un poquito en los últimos decimales y en los resultados de ''predict'' prácticamente son iguales.
Lo único extraño es que con "Google Colab con T4 GPU y tensorflow 2.14" distintas ejecuciones no daban exactamente el mismo resultado.