ium_z434743/training.py

55 lines
1.5 KiB
Python
Raw Normal View History

2023-05-12 18:15:27 +02:00
import pandas
import os
from sacred import Experiment
from sacred.observers import MongoObserver
from sacred.observers import FileStorageObserver
from keras.applications.densenet import layers
import tensorflow
import random
exint = Experiment('z-s434743-training')
2023-05-12 19:22:18 +02:00
2023-05-12 18:15:27 +02:00
exint.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1:27017',
db_name='sacred'))
exint.observers.append(FileStorageObserver('z-s434743-training/master'))
2023-05-12 19:22:18 +02:00
2023-05-12 18:15:27 +02:00
@exint.config
def my_config():
EPOCHS = int(os.environ['EPOCHS'])
@exint.main
def my_main(EPOCHS, _run):
2023-05-12 19:22:18 +02:00
_run.info["epochs"] = EPOCHS
2023-05-12 18:15:27 +02:00
normalize = layers.Normalization()
train_data_x = pandas.read_csv('./X_train.csv')
_run.info["data"] = train_data_x
movies_all = train_data_x.copy()
movies_predict = train_data_x.pop('audienceScore')
normalize.adapt(movies_all)
norm_movies_model = tensorflow.keras.Sequential([
normalize,
layers.Dense(64),
layers.Dense(1)
])
norm_movies_model.compile(
loss=tensorflow.keras.losses.MeanSquaredError(),
optimizer=tensorflow.keras.optimizers.Adam())
norm_movies_model.fit(movies_all, movies_predict, epochs=EPOCHS)
counter = 0
while counter < 20:
counter+=1
value = counter * random.randint(5, 5000)
_run.log_scalar("training.accuracy", value * 2)
norm_movies_model.save('test')
exint.run()
2023-05-12 19:22:18 +02:00
2023-05-12 18:15:27 +02:00
exint.add_artifact('test/saved_model.pb')
2023-05-12 19:22:18 +02:00
2023-05-12 18:15:27 +02:00
exint.add_source_file('./ium_z434743/train.py')