Sytem Utility

System command line

In [ ]:
# Colab Tiips

# !cat /etc/issue                          # os info
# !free -h                                 # memory info
# !cat /proc/cpuinfo                       # cpu info
# !mkdir test                              # make directory
# !ls 'sample_data/'                       # list files
# %cd test                                 # change directory
# !echo 'test' > test.txt                  # create file
# !mv test.txt  '/content/drive/My Drive'  # move file
# !pip install tensorflow==1.8.0           # install library

Library

In [ ]:
# Import Library
import os
import numpy as np
import pandas as pd
from datetime import datetime
import warnings
warnings.filterwarnings("ignore")
In [ ]:
# Get Package Version 

import platform
print("python " + platform.python_version())

import tensorflow as tf
print("tensorflow " + tf.__version__)
python 3.6.9
tensorflow 2.2.0-rc3

File Management

In [ ]:
# List file

% ls sample_data/
anscombe.json*                mnist_test.csv
california_housing_test.csv   mnist_train_small.csv
california_housing_train.csv  README.md*
In [ ]:
# Upload file from local

from google.colab import files
uploaded = files.upload()
Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable.
In [ ]:
# Upload file from kaggle

import os
os.environ['KAGGLE_USERNAME'] = "jingwora1" # username from the json file
os.environ['KAGGLE_KEY'] = "92dbfea6346fc608e08b8b31383520d2" # key from the json file
!kaggle datasets download -d rush4ratio/video-game-sales-with-ratings # api copied from kaggle

#zipファイルを開放して削除する
!unzip \*.zip  && rm *.zip
Downloading video-game-sales-with-ratings.zip to /content
  0% 0.00/476k [00:00<?, ?B/s]
100% 476k/476k [00:00<00:00, 64.8MB/s]
Archive:  video-game-sales-with-ratings.zip
replace Video_Games_Sales_as_at_22_Dec_2016.csv? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: Video_Games_Sales_as_at_22_Dec_2016.csv  
In [ ]:
# Upload file from wikimedia

import urllib
img_src = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/64_365_Color_Macro_%285498808099%29.jpg/320px-64_365_Color_Macro_%285498808099%29.jpg"
img_path = 'input_image.jpg'
urllib.request.urlretrieve(img_src, img_path)
In [ ]:
# Show image

from IPython.display import Image,display_jpeg
img_path = 'input_image.jpg'
display_jpeg(Image(img_path))
In [ ]:
# Create folder

output_dir = ('output/')
if not os.path.exists(output_dir):
    os.makedirs(output_dir)
In [ ]:
# Download file

from google.colab import files

output_path = 'sample_data/california_housing_train.csv'
files.download(output_path)
In [ ]:
# Mount with g-drive

from google.colab import drive
drive.mount('/content/drive')
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
In [ ]:
! ls 'drive/My Drive/dataset/time/'
# Show files
AirPassengers.csv  data2.csv  pollution_beijing.txt  tokyo_weather.csv
aus_airport.csv    data.csv   response_times.csv
bitcoin.csv	   input.csv  sample_data

Timing

In [ ]:
import time

start_time = time.time()

print('Duration: {:.4f} seconds'. format(time.time() - start_time))
Duration: 0.0000 seconds
In [ ]: