forked from afshinea/keras-data-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keras_script.py
executable file
·38 lines (32 loc) · 1.07 KB
/
keras_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
import tensorflow as tf
from my_classes import DataGenerator
from tensorflow.keras import datasets, layers, models
# Parameters
params = {'dim': (32,32,32),
'batch_size': 64,
'n_classes': 6,
'n_channels': 1,
'shuffle': True}
# Datasets
partition = {
'train': ['id-1', 'id-2', 'id-3'],
'validation': ['id-4']} # IDs
labels = {'id-1': 0, 'id-2': 1, 'id-3': 2, 'id-4': 1} # Labels
# Generators
training_generator = DataGenerator(partition['train'], labels, **params)
validation_generator = DataGenerator(partition['validation'], labels, **params)
model = models.Sequential()
model.add(layers.Dense(16, activation='relu', input_shape=(1240,)))
model.add(layers.Dense(1, activation='linear'))
model.summary()
model.compile(
optimizer='adam',
loss=tf.keras.losses.MeanSquaredError(),
metrics=['mse']
)
# Train model on dataset
model.fit_generator(generator=training_generator,
validation_data=validation_generator,
use_multiprocessing=True,
workers=6)