Recently, Google Colab removed the support to Tensorflow 1.x, as shown in the update log of 2022/08/11, and I coudn't run the TempoGAN.
But there is still a way to do it through miniconda.
Just copy and paste the code below in your Colab noteboook, change the path to your net in your Google Drive and install the dependencies you need. Here, I needed "imageio, keras 2.3 and protobuf 3.20".
Note: I broke some lines for better reading here. In Colab, you will need to undo this.
from google.colab import drive
import os, sys
def install_python37():
!sudo apt-get install python3.7
!sudo apt-get update -y
!sudo update-alternatives --install /usr/bin/python3
python3 /usr/bin/python3.7 1
!sudo update-alternatives --config python3
def install_miniconda():
install_python37()
!which python
!python --version
!echo 'PYTHONPATH' $PYTHONPATH
%env PYTHONPATH=
!echo 'PYTHONPATH' $PYTHONPATH
#######################################################
# INSTALL CONDA ON GOOGLE COLAB
#######################################################
!wget https://repo.anaconda.com/miniconda/
Miniconda3-py37_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py37_4.12.0-Linux-x86_64.sh
!bash ./Miniconda3-py37_4.12.0-Linux-x86_64.sh
-b -f -p /usr/local/
!which conda
!conda --version
#######################################################
# UPDATING CONDA ON GOOGLE COLAB
#######################################################
!conda install --channel defaults conda python=3.7 --yes
!conda update --channel defaults --all --yes
###
from psutil import virtual_memory
ram_gb = virtual_memory().total / 1e9
print('Your runtime has {:.1f} gigabytes of
available RAM\n'.format(ram_gb))
if ram_gb < 20:
print('Not using a high-RAM runtime')
else:
print('You are using a high-RAM runtime!')
###
gpu_info = !nvidia-smi
gpu_info = '\n'.join(gpu_info)
if gpu_info.find('failed') >= 0:
print('Not connected to a GPU')
else:
print(gpu_info)
###
install_miniconda()
sys.path.append('/usr/local/lib/python3.7/dist-packages')
for p in sys.path:
print(p)
!conda --version
!conda create --name TempoGAN python=3.7
# https://stackoverflow.com/questions/53031430/conda-environment-
in-google-colab-google-colaboratory
!source activate TempoGAN && conda list
!source activate TempoGAN && pip install protobuf==3.20.*
!source activate TempoGAN && pip install scipy==1.2.0 !source activate TempoGAN && pip install imageio keras==2.3
!source activate TempoGAN && pip install tensorflow-gpu==1.15
currentDir = '/content/gdrive/My Drive/'
def mountGD():
print("Mounting Google Drive")
drive.mount('/content/gdrive')
def unmountGD():
print("Unmounting Google Drive")
drive.flush_and_unmount()
if (os.path.exists(currentDir) == True):
print('Path found')
# if this returns a shell error, restart the runtime
print(os.getcwd())
else:
mountGD()
def change_dir(directory):
os.chdir(directory) # changing current directory
print(os.getcwd())
sys.path.append(directory)
currentDir = '/content/gdrive/My Drive/TempoGAN/tensorflow/tempoGAN'
change_dir(currentDir)
print('Start')
!source activate TempoGAN && python example_run_output.py
No comments:
Post a Comment