Python comandi per operare in Colab Notebooks
Tensorflow-Quantum
#SETUP
try:
# %tensorflow_version only works in Colab
%tensorflow_version 2.x
except Exception:
pass
#INSTALL
!pip install tensorflow-quantum
import tensorflow as tf
import tensorflow_quantum as tfq
import cirq
import sympy
import numpy as np
#VISUALIZATION TOOLS
%matplotlib inline
import matplotlib.pyplot as plt
from cirq.contrib.svg import SVGCircuit
Comando per installare software
!pip install soundfile
Comando per importare file from drive
from google.colab import drive
drive.mount('/content/drive')
Import files from drive with pandas
file1 = pd.read_csv('/content/drive/My Drive/Colab Notebooks/...../*.csv', header=0)
Lista files from drive
import os
lista =os.listdir('/content/drive/My Drive/Colab Notebooks/.../')
Save data into drive
import joblib
joblib.dump(dati_da_salvare, '/content/drive/My Drive/Colab Notebooks/..../nome_file')
Downloads file da Colab to your computer
from google.colab import files
files.download('nome_file')
Identificare TPU per la configurazione TensorFlow
TPU_WORKER = 'grpc://' + os.environ['COLAB_TPU_ADDR']
tf.logging.set_verbosity(tf.logging.INFO)
tsu_model = tf.contrib.tpu.keras_to_tpu_model(
model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)))
Salvare documenti da Colab a bucket S3 su AWS
import boto3
import joblib
s3r = boto3.resource('s3', aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
bucket = s3r.Bucket('nome_bucket').put_object(Key = 'example.wav', Body='example.wav')
oppure con joblib --> import joblib
joblib.dump(nome_array,
"s3r.Bucket('nome_bucket').put_object(Key='example_array.pkl',Body='example_array.pkl')")
Salvare i dati da Colab a Google Cloud Platform (GCP)
#mount drive
from google.colab import auth
auth.authenticate_user()
from google.colab import drive
drive.mount('/content/drive')
project_id = 'my-project-name'
#connect with cgp
!gcloud config set project {project_id}
!gsutil ls
#define output
bucket_name = 'my-bucket'
#copy file from ... to ....
!gsutil -m cp -r /content/drive/My\ Drive/Colab\ Notebooks/tts/data/* \
gs://{bucket_name}
Python comandi per generare file eseguibili in Windows
PyInstaller
pip install PyInstaller
pyinstaller -wF nome_programma.py
Nuitka
install mingGW64 64 bit su c:\MinGW64
install Python
install Nuitka
python -m nuitka --mingw64 --standalone --show-progress nome_programma.py