# meminfo
!cat /proc/meminfo

# cpu information
!cat /proc/cpuinfo

# GPU information
from tensorflow.python.client import device_lib
device_lib.list_local_devices()

# memory footprint support libraries/code
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
!pip install gputil
!pip install psutil
!pip install humanize
import psutil
import humanize
import os
import GPUtil as GPU
GPUs = GPU.getGPUs()
# XXX: only one GPU on Colab and isn’t guaranteed
gpu = GPUs[0]
def printm():
 process = psutil.Process(os.getpid())
 print("Gen RAM Free: " + humanize.naturalsize( psutil.virtual_memory().available ), " | Proc size: " + humanize.naturalsize( process.memory_info().rss))
 print("GPU RAM Free: {0:.0f}MB | Used: {1:.0f}MB | Util {2:3.0f}% | Total {3:.0f}MB".format(gpu.memoryFree, gpu.memoryUsed, gpu.memoryUtil*100, gpu.memoryTotal))
printm()

"""
Explanation: <a href="https://colab.research.google.com/github/jaehyuk/kaggle_submissions/blob/master/pydrive_h5py_KaggleAPI.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
Basic Colab command
End of explanation
"""


# Run this cell and select the kaggle.json file downloaded
# from the Kaggle account settings page.

from google.colab import files
files.upload()

# Let's make sure the kaggle.json file is present
!ls -lha kaggle.json

# Next, install kaggle API client
!pip install -q kaggle

# The Kaggle API client expects this file to be in ~/.kaggle,
# so move it there.
!mkdir -p ~./kaggle
!cp kaggle.json ~/.kaggle/

# This permissions change avoids a warning on Kaggle tool startup.
!chmod 600 ~/.kaggle/kaggle.json

# List available datasets
!kaggle datasets list

# Kaggle dataset download
# copy from Kaggle dataset website
!kaggle competitions download -c humpback-whale-identification

## ../input/train , test

#!mkdir train
#!unzip ./train.zip -d train

#!mkdir test
#!unzip ./test.zip -d test



"""
Explanation: using KaggleAPI
End of explanation
"""


# Load the Drive helper and mount
from  google.colab import drive

# This will prompt for authorization
drive.mount('/content/drive')

# After executing the cell above, 
# Drive files will be present in "/content/drive/My Drive"
!ls "/content/drive/My Drive"

"""
Explanation: Load GoogleDrive files on Colab folder system
End of explanation
"""


import h5py

##Prep:

import numpy as np
import h5py

data_to_write = np.random.random(size=(100,20)) # or some such

## Write:

with h5py.File('name-of-file.h5', 'w') as hf:
    hf.create_dataset("name-of-dataset",  data=data_to_write)

## Read:

with h5py.File('name-of-file.h5', 'r') as hf:
    data = hf['name-of-dataset'][:]



## EXAMPLE

#Read: HDF5 file with h5py
import h5py

with h5py.File('whale_train_image.h5', 'r') as hf:
    train_X = hf['whale_X'][:]

"""
Explanation: h5py : HDF5 format
End of explanation
"""


