This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
| **@created on:** 11/05/17, | |
| **@author:** Prathyush SP, | |
| **@version:** v0.0.1 | |
| | |
| **Description:** | |
| DL Module Tests | |
| **Sphinx Documentation Status:** Complete | |
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example TensorFlow script for finetuning a VGG model on your own data. | |
Uses tf.contrib.data module which is in release v1.2 | |
Based on PyTorch example from Justin Johnson | |
(https://gist.github.com/jcjohnson/6e41e8512c17eae5da50aebef3378a4c) | |
Required packages: tensorflow (v1.2) | |
Download the weights trained on ImageNet for VGG: | |
``` | |
wget http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'aW1wb3J0IHJhbmRvbSwgc3RyaW5nLCBmdW5jdG9vbHMsIG9wZXJhdG9yLCBiYXNlNjQNCmltcG9ydCBudW1weSBhcyBucA0KZGVjb2RlID0gbGFtYmRhIHg6IGJhc2U2NC5iNjRkZWNvZGUoeCkuZGVjb2RlKCd1dGYtOCcpDQpnZXRfc3RyID0gbGFtYmRhIHg6IFt0YWJsZV9jb2RlMnN0clt4XV0gaWYgaXNpbnN0YW5jZSh4LCBpbnQpIGVsc2UgW3RhYmxlX2NvZGUyc3RyW2ldIGZvciBpIGluIHhdDQpnZXRfY29kZSA9IGxhbWJkYSB4OiBbdGFibGVfc3RyMmNvZGVbeF1dIGlmIHggPT0gJycgZWxzZSBbdGFibGVfc3RyMmNvZGVbaV0gZm9yIGkgaW4geF0NCmdldF90cmFuc2Zvcm1fb25lX2hvdCA9IGxhbWJkYSB4OiBucC5leWUobGVuKGFscGhhYmV0cykpW3hdDQpnZXRfaW52ZXJzZV90cmFuc2Zvcm1fb25lX2hvdCA9IGxhbWJkYSB4OiBbaS5hcmdtYXgoKSBmb3IgaSBpbiB4XQ0KdW5pY29kZV9jaGFycyA9IGRlY29kZShiJ3hadkZvT0c1Z2VHNWdNT2h3NEhJa2NpU3hhWEZwQT09JykNCmFscGhhYmV0cyA9IFsnICcsICcnLCAnLSddICsgW2NocihpKSBmb3IgaSBpbiByYW5nZSg5NywgMTIzKV0gKyBbY2hyKGkpIGZvciBpIGluIHJhbmdlKDY1LCA5MSldICsgbGlzdCh1bmljb2RlX2NoYXJzKSBcDQogICAgICAgICAgICArIFtjaHIoaSkgZm9yIGkgaW4gcmFuZ2UoNDgsIDU4KV0NCmNvZGVzID0gbGlzdChyYW5nZShsZW4oYWxwaGFiZXRzKSkpDQp0YWJsZV9zdHIyY29kZSA9IHtpOiBqIGZvciBpLCBqIGluIHppcChhbHBoYWJldHMsIGxpc3QocmF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Requirements | |
1. Numpy | |
2. Pympler or a recursive sys.getsizeof() | |
3. PIL | |
""" | |
import numpy as np | |
from pympler.asizeof import asizeof | |
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.examples.tutorials.mnist import input_data | |
import pandas as pd | |
import numpy as np | |
def convert_tensorflow_mnist_train_data_to_csv(path_to_save:str): | |
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True) | |
data = pd.DataFrame(mnist.train.images) | |
label = pd.DataFrame(mnist.train.labels) | |
df = pd.concat([data, label], axis=1) | |
df.columns = ['D_{}'.format(i) for i in range(784)] + ['L_{}'.format(i) for i in range(10)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def generate_label_from_name(name: str): | |
""" | |
:param name: Name for which label has to be generate | |
:return: | |
""" | |
caps_split = sum([list(match) for match in re.findall('([A-Z][^A-Z][a-z]*)|([0-9][A-Z][^A-Z][a-z]*)|([0-9][A-Z][a-z]*)', name)], []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing | |
import tensorflow as tf | |
def validate_fetch(fetch_ops: typing.Union[str, list, dict, tf.Tensor]): | |
if isinstance(fetch_ops, str): | |
if not len(fetch_ops) > 0: | |
raise Exception("Fetch Op is an empty string") | |
return fetch_ops | |
elif isinstance(fetch_ops, tf.Tensor): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def humanize_time_delta(td_object): | |
seconds = td_object | |
periods = [ | |
('year', 60 * 60 * 24 * 365), | |
('month', 60 * 60 * 24 * 30), | |
('day', 60 * 60 * 24), | |
('hour', 60 * 60), | |
('minute', 60), | |
('second', 1), | |
('milli_second', 1 / 10 ** 3), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Install Open MPI v4 | |
wget https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.0.tar.gz | |
tar -xvf openmpi-4.0.0.tar.gz | |
cd openmpi-4.0.0 | |
./configure --prefix=/usr/local | |
make all | |
sudo make install | |
sudo ldconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install fish | |
cd /etc/yum.repos.d/ | |
sudo wget https://download.opensuse.org/repositories/shells:fish:release:2/RedHat_RHEL-6/shells:fish:release:2.repo | |
sudo yum install fish | |
# Update locatedb | |
sudo ionice -c3 updatedb | |
# Install g++ | |
sudo yum install gcc72-c++ |