This page assumes that you've followed the instructions to install TensorFlow using conda and successfully installed TF in your conda environment. Below we provide more TF model training code for you to fully test your installation. Remember to log onto dev-amd20-v100.
All the code should be typed in (or copy-paste) to an interactive python interpreter, after running the first four lines below from your terminal. After you are done and have quit the python session, remember to deactivate your conda environment via conda deactivate.
1 2 3 4 5 6 7 8 910
# [Insert command to load your Conda] -- see https://docs.icer.msu.edu/Using_conda/
condaactivatetf_Jul2024
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib:/mnt/home/user123/miniforge3/envs/tf_Jul2024/lib/python3.10/site-packages/tensorrt
python
# [Insert your python code after >>> the prompt of the interactive Python interpreter]
condadeactivate
Code 1
1 2 3 4 5 6 7 8 910111213141516171819202122232425
importtensorflowastfimportnumpyasnp# Generate random datax=np.random.rand(100,10)y=np.random.randint(0,2,size=(100,))# Define the model architecturemodel=tf.keras.models.Sequential([tf.keras.layers.Dense(64,activation='relu',input_shape=(10,)),tf.keras.layers.Dense(32,activation='relu'),tf.keras.layers.Dense(1,activation='sigmoid')])# Compile the modelmodel.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])# Train the modelmodel.fit(x,y,epochs=10,validation_split=0.2)# Evaluate the model on test datatest_loss,test_acc=model.evaluate(x,y,verbose=2)print(f'Test accuracy: {test_acc}')