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
exportPATH=/mnt/home/user123/anaconda3/bin:$PATH
condaactivatetf_gpu_Feb2023
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/:/lib64/:$CONDA_PREFIX/lib/:$CONDA_PREFIX/lib/python3.9/site-packages/tensorrt_libs
exportXLA_FLAGS=--xla_gpu_cuda_data_dir=$CONDA_PREFIX/lib
python
# Here 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}')