Skip to content

Commit

Permalink
tensorflow example
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeiland committed Feb 22, 2024
1 parent e7397aa commit 98a0e6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/TensorFlow/cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
from tensorflow.keras import datasets, layers, models

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0

model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))

model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

model.summary()

history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))

test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)

print(test_acc)

model.save('my_model.keras')


7 changes: 7 additions & 0 deletions examples/TensorFlow/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TensorFlow example

Simple example from the tutorial; make sure to use the datamover to pick up the cifar.py script

```
sbatch -p f4s --datamover=simple ./runscript.sh
```
9 changes: 9 additions & 0 deletions examples/TensorFlow/runscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo mount -t cvmfs software.eessi.io /cvmfs/software.eessi.io
source /cvmfs/software.eessi.io/versions/2023.06/init/bash

ml load TensorFlow
cd outputs

#python -c "import tensorflow as tf; tf.keras.datasets.cifar10.load_data()"
python ../cifar.py

0 comments on commit 98a0e6d

Please sign in to comment.