Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
# this code is taken from https://www.tensorflow.org/tutorials/keras/classification 
# the code was modified to using pre-downloaded data instead of downloading from the API.
# Tensorflow version 2.3.1

import tensorflow as tf
import numpy as np

fashion_mnist = tf.keras.datasets.fashion_mnist
#(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

with open('mnist_data.npy', 'rb') as f: 
    train_images = np.load(f)
    train_labels = np.load(f)
    test_images = np.load(f)
    test_labels = np.load(f)

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

# Explore Data
train_images.shape
len(train_labels)

test_images.shape
len(test_labels)

# Preprocess Data
train_images = train_images / 255.0
test_images = test_images / 255.0

tf.debugging.set_log_device_placement(True)
strategy = tf.distribute.MirroredStrategy()

with strategy.scope() :
    model = tf.keras.Sequential([
        tf.keras.layers.Flatten(input_shape=(28, 28)),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dense(10)
    ])

    model.compile(optimizer='adam',
                  loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
                  metrics=['accuracy'])

model.fit(train_images, train_labels, epochs=10)

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

print('\n Test loss:', test_loss)
print('\nTest accuracy:', test_acc)

# MIT License
#
# Copyright (c) 2017 François Chollet
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

ไฟล์

...

Submit.sh

Code Block
#!/bin/bash
#SBATCH -p gpu                           # Specify partition [Compute/Memory/GPU]
#SBATCH -N 1 -c 16   			         # Specify number of nodes and processors per task
#SBATCH --gpus-per-node=4		         # Specify number of GPU per task
#SBATCH --ntasks-per-node=4		         # Specify tasks per node
#SBATCH -t 120:00:00                     # Specify maximum time limit (hour: minute: second)
#SBATCH -A ltxxxxxx               	     # Specify project name
#SBATCH -J JOBNAME               	     # Specify job name
module load Apptainer/1.1.6              # Load the Apptainer module
apptainer exec --nv -B $PWD:$PWD tensorflow_2.3.1-gpu.sif python3 MNIST.py       # Run your program

...

  1. ดาวน์โหลด Data set โดยใช้คำสั่งต่อไปนี้

Code Block
username@lanta:~> ml Apptainer
username@lanta:~> apptainer exec tensorflow_2.3.1-gpu.sif python Setup.py
  1. จากนั้น ใช้คำสั่ง sbatch submit.sh เพื่อส่ง Job ของคุณเข้าระบบ Slurm ของ LANTA

Code Block
username@lanta:~> sbatch submitSubmit.sh