Skip to content

Commit f6537e3

Browse files
committed
data augmentation
1 parent 4068dd8 commit f6537e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+460
-3306
lines changed

codes/python/0-welcome/README.rst

Lines changed: 0 additions & 70 deletions
This file was deleted.

codes/python/0-welcome/code/0-welcome.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

codes/python/0-welcome/code/TensorFlow_Test.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

codes/python/0-welcome/welcome.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
"""welcome.ipynb
3+
4+
Automatically generated by Colaboratory.
5+
6+
Original file is located at
7+
https://colab.research.google.com/github/instillai/TensorFlow-Course/blob/master/codes/ipython/0-welcome/welcome.ipynb
8+
"""
9+
10+
# Import tensorflow
11+
import tensorflow as tf
12+
13+
# Check version
14+
print("Tensorflow version: ", tf.__version__)
15+
16+
# Test TensorFlow for cuda availibility
17+
print("Tensorflow is built with CUDA: ", tf.test.is_built_with_cuda())
18+
19+
# Check devices
20+
print("All devices: ", tf.config.list_physical_devices(device_type=None))
21+
print("GPU devices: ", tf.config.list_physical_devices(device_type='GPU'))
22+
23+
# Print a randomly generated tensor
24+
# tf.math.reduce_sum: https://www.tensorflow.org/api_docs/python/tf/math/reduce_sum
25+
# tf.random.normal: https://www.tensorflow.org/api_docs/python/tf/random/normal
26+
print(tf.math.reduce_sum(tf.random.normal([1, 10])))
27+

codes/python/1-basics/tensors.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# -*- coding: utf-8 -*-
2+
"""tensors.ipynb
3+
4+
Automatically generated by Colaboratory.
5+
6+
Original file is located at
7+
https://colab.research.google.com/github/instillai/TensorFlow-Course/blob/master/codes/ipython/1-basics/tensors.ipynb
8+
"""
9+
10+
# Import necessary libraries
11+
import tensorflow as tf
12+
import numpy as np
13+
14+
"""## Tensors
15+
16+
Tensor are multi-dimensitonal arrays that are used in Tensorflow.
17+
18+
We use the following definition:
19+
20+
* **Rank:** The number of dimensions that a vector has.
21+
22+
Below, we will define different kinds of tensors and show their rank using [tf.rank](https://www.tensorflow.org/api_docs/python/tf/rank) function.
23+
"""
24+
25+
tensor = tf.constant(0)
26+
print("Print constant tensor {} of rank {}".format(tensor, tf.rank(tensor)))
27+
print("Show full tensor:", tensor)
28+
29+
# NOTE: We use .numpy() to transform tf.tensor to numpy
30+
tensor = tf.constant([1,2,3])
31+
print("Tensor:", tensor)
32+
print("Rank:", tf.rank(tensor).numpy())
33+
34+
"""### Tensor Operations"""
35+
36+
x = tf.constant([[1, 1],
37+
[1, 1]])
38+
y = tf.constant([[2, 4],
39+
[6, 8]])
40+
41+
# Add two tensors
42+
print(tf.add(x, y), "\n")
43+
44+
# Add two tensors
45+
print(tf.matmul(x, y), "\n")
46+
47+
"""### Muti-dimentional Tensors
48+
49+
This part is not much different compared to what we learned so far. However, it would be nice to try extracting as much information as we can from a multi-dimentional tensor.
50+
51+
52+
Let's use [tf.ones](https://www.tensorflow.org/api_docs/python/tf/ones) for our purpose here. It creates an all-one tensor.
53+
"""
54+
55+
# We set the shape of the tensor and the desired data type.
56+
tensor = tf.ones(shape = [2, 3, 6], dtype = tf.float32)
57+
print('Tensor:', tensor)
58+
59+
print("Tensor Rank: ", tf.rank(tensor).numpy())
60+
print("Shape: ", tensor.shape)
61+
print("Elements' type", tensor.dtype)
62+
print("The size of the second axis:", tensor.shape[1])
63+
print("The size of the last axis:", tensor.shape[-1])
64+
print("Total number of elements: ", tf.size(tensor).numpy())
65+
print("How many dimensions? ", tensor.ndim)
66+
67+
"""### Indexing
68+
69+
TensorFlow indexing is aligned with Python indexing. See the following examples.
70+
"""
71+
72+
x = tf.constant([[1, 2, 3],
73+
[4, 5, 6],
74+
[7, 8, 9]])
75+
76+
# All elements
77+
print(x[:].numpy())
78+
79+
# All elements of the first row
80+
print(x[0,:].numpy())
81+
82+
# First row and last column
83+
print(x[0,-1].numpy())
84+
85+
# From second row to last and from third column to last
86+
print(x[1:,2:].numpy)
87+
88+
"""### Data types
89+
90+
You can change the data type of the tesnorflow tensors for your purpose. This will be done easily by [tf.cast](https://www.tensorflow.org/api_docs/python/tf/cast).
91+
"""
92+
93+
original_tensor = tf.constant([1, 2, 3, 4], dtype=tf.int32)
94+
print('Original tensor: ', original_tensor)
95+
print("Tensor type before casting: ", original_tensor.dtype)
96+
97+
# Casting to change dtype
98+
casted_tensor = tf.cast(original_tensor, dtype=tf.float32)
99+
print('New tensor: ', casted_tensor)
100+
print("Tensor type after casting: ", casted_tensor.dtype)
101+

codes/python/basics_in_machine_learning/linear_regression/README.rst

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)