Author- AI Legend
20Feb|2024|03min read

Tensorflow...



Let's discuss little bit about TensorFlow ...It is a libre open source software which is also said to be "FLOSS" and originated via Google researchers and scientists. Generally we utilized it to speed the machine learning , deep learning and other various arithmetical forecasting or prescriptive analytics consignments.
Tensorflow also depicted to prune the procedure over generating and implementing proceeded data interpretation approach like prediction, forecasting , arithematical and data science modellers .A modeller that create theoretical descriptions of techniques or procedure for the prediction and development.
Here, TensorFlow software manipulate a collection of data which generally positioned even as a computational vertex in tabulation or graphical shape, we can say. Let's understand, What is tensor? In general, Tensor is a tabulation in which we produce the outline and vertex that can depict the multidimensional matrices or vertex especially where very large dataset computations accomplished like neural network.

If I talk about, what is Tensorflow? Then,we probably say, Its flexible architecture allows for the easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters of servers to mobile and edge devices.

Numpy

Now let's gain some info regarding the strongest library of python i.e numPy. So Numpy, we can say one of the very influencive libraries in Python libraries, and afterthat consistency and unification in the data structure provided via Tensorflow efficiently. .Accordingly, we can say integrated Tensorflow enables us to build complex input pipelines,null chunks. For example NDarrays, the library's initial datatype, which spontaneously converted into TensorFlow Tensors in TF operations; similar we can say also vericious or else vice-versa. That permits as dual libraries can perform task simultaneously at a time in the absence of operator who ca withoutrequiring the user to write explicit data conversions. Moreover, the integration extends to memory optimization by having TF Tensors share the underlying memory representations of Numpy NDarrays whenever possible

Google Colab

As I am using Colab, released via Google, a TensorFlow Jupyter notebook environment which is not demanding any updation. We can use it in browser also. that provides free access to GPUs and the storage and also share notebooks on Google Drive.

Let's perform some coding of tensorflow



# firstly we need to import required libraries

import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np



# Now let's download tensorflow integrated config file we generally used...

tf.config.experimental.list_logical_devices()


result :: [LogicalDevice(name='/device:CPU:0', device_type='CPU'), LogicalDevice(name='/device:GPU:0', device_type='GPU')]
# Now here tensorflow built with Cuda toolkit to installation ad dowloading for compatibility with tensorflow

tf.test.is_built_with_cuda()


result :: True
# Now let's splitting the data into training dataset and testing dataset from tensorflow

(X_train, y_train), (X_test,y_test) = tf.keras.datasets.cifar10.load_data()


result :: Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz 170498071/170498071 [==============================] - 6s 0us/step
# Now let's visualize the data through plotting the graph

def plot_sample(index): plt.figure(figsize = (10,1)) plt.imshow(X_train[index])


#After that we have get an image of deer from our dataset ....

plot_sample(3)


# Now let's creat the classes

classes = ["airplane","automobile","bird", "cat","deer","dog","frog","horse","ship","truck"]


# Now let's choose via randomly entering any counting like I have put 3,0 in y-training dataset

classes[y_train[3][0]]

result :: "deer"


# Here we are manipulating our data or we can say scaling to detrmine the best results right

X_train_scaled = X_train / 255 X_test_scaled = X_test / 255


# Here we are converting numerical dataset to categorical form keras utility ie to_categorical() before pass it from our model.If our training dataset using as classes as integers,then to_categorical can convert it into proper vector form using with model. We can't easily train classification model without that conversion.

y_train_categorical = keras.utils.to_categorical( y_train, num_classes=10, dtype='float32' ) y_test_categorical = keras.utils.to_categorical( y_test, num_classes=10, dtype='float32' )


# Now create our model, here we are building our model from keras sequential API. As keras is a high level API for building and training neural network. A linear stack of layers ito tf.keras.Sequential said to be Sequential group alright.


Now let's discuss briefly about all the layers present in our model ::

Convolutional layer: CNN Layer is used to process the image — used for convolutional neural networks.
Recurrent layer: Recurrent layer is used to process sequencial form of data — used for recurrent neural networks.
MaxPooling layer:MaxPooling layer used to down-sampling attribute by taking the maximum value in non-overlapping rectangular blocks — used to sustain important attributes also reducing the probability overfitting.
Flatten layer: Flatten layer used to flattens the multi-dimensional input tensors into a single dimension — utilized as a transformation layer in between convolutional or recurrent layers and fully connected layers in a neural network.
Layer: A layer generally used to put down input units to 0 randomly (using a defined frequency) during training time —utilized as a regularization technique for preserving the overfitting in neural networks.
Embedding layer: Embedding layer: a layer that represents words or phrases in a high-dimensional vector space — used to map words or phrases to dense vectors for use as input to a neural network.

Now we compile our model ,here we used optimizer as

SGD : As Gradient Descent is an iterative optimization process which generally used to searche an objective function’s optimum value (Minimum/Maximum). It is one of the most used methods for changing a model’s parameters in order to reduce a cost function in machine learning, we ca say...
Categorical Cross Entropy :Categorical Cross Entropy is aloss function mainly used for multi-class classification model in which two or more than two outputs labels.It produces a one-hot array sustaining the expected match.
Accuracy:An accuracy i metrics can be determined as a simple comparison between how many target values matches the predicted values.


model = keras.Sequential([ keras.layers.Flatten(input_shape=(32,32,3)), keras.layers.Dense(3000, activation='relu'), keras.layers.Dense(1000, activation='relu'), keras.layers.Dense(10, activation='sigmoid') )]

model.compile( optimizer='SGD', loss='categorical_crossentropy', metrics=['accuracy'])

model.fit(X_train_scaled, y_train_categorical, epochs=5)



result :: Epoch 1/5 1563/1563 [==============================] - 8s 4ms/step - loss: 1.8099 - accuracy: 0.3551 Epoch 2/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.6204 - accuracy: 0.4269 Epoch 3/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.5408 - accuracy: 0.4569 Epoch 4/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.4799 - accuracy: 0.4774 Epoch 5/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.4297 - accuracy: 0.4969


# predicting the model..

np.argmax(model.predict(X_test_scaled)[0])


# for achieving high accuracy iterating the task

def get_model(): model = keras.Sequential([ keras.layers.Flatten(input_shape=(32,32,3)), keras.layers.Dense(3000, activation='relu'), keras.layers.Dense(1000, activation='relu'), keras.layers.Dense(10, activation='sigmoid') )]

model.compile( optimizer='SGD', loss='categorical_crossentropy', metrics=['accuracy'])

return model


# Here we go to enjoy the storyteller bot, which is ready to give us output...

%%timeit -n1 -r1 with tf.device('/CPU:0'): cpu_model = get_model() cpu_model.fit(X_train_scaled, y_train_categorical, epochs=5)


result :: Epoch 1/5
1563/1563 [==============================] - 79s 50ms/step - loss: 1.8111 - accuracy: 0.3549 Epoch 2/5 1563/1563 [==============================] - 77s 49ms/step - loss: 1.6228 - accuracy: 0.4294 Epoch 3/5 1563/1563 [==============================] - 77s 49ms/step - loss: 1.5435 - accuracy: 0.4573 Epoch 4/5 1563/1563 [==============================] - 80s 51ms/step - loss: 1.4849 - accuracy: 0.4774 Epoch 5/5 1563/1563 [==============================] - 79s 50ms/step - loss: 1.4336 - accuracy: 0.4964 6min 32s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
# Here we repeating the process to get more accuracy in our model.. through GPU...

%%timeit -n1 -r1 with tf.device('/GPU:0'): gpu_model = get_model() gpu_model.fit(X_train_scaled, y_train_categorical, epochs=5)


result :: Epoch 1/5
1563/1563 [==============================] - 6s 4ms/step - loss: 1.8112 - accuracy: 0.3545 Epoch 2/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.6253 - accuracy: 0.4266 Epoch 3/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.5435 - accuracy: 0.4542 Epoch 4/5 1563/1563 [==============================] - 6s 4ms/step - loss: 1.4828 - accuracy: 0.4776 Epoch 5/5 1563/1563 [==============================] - 8s 5ms/step - loss: 1.4338 - accuracy: 0.4923 42.6 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)


Application

Medical

As per analysis , medical growing vastly in AI field... GE Healthcare utilizing TensorFlow to enhance the velocity and accuracy of MRIs to identify distinct body parts. Google utilized TensorFlow to create DermAssist, a free mobile application which permits users to capture images of their skin and spot future health complications. Sinovation Ventures utilized TensorFlow to spot and classify eye diseases from optical coherence tomography (OCT) scans.

Social media

Let's discuss about twitter, Twitter executed TensorFlow to rank tweets by noteworthiness for a specified user, and replaced its podium to be visible tweets in sequence this ranking. Priorly, tweets were directly shown in transpose chronological order. The photo sharing app VSCO utilixed TensorFlow to assist suggest custom filters for pictures.

Search Engine

If we talk about search engine, Google officially released RankBrain on October 26, 2015, backed by TensorFlow.

Education

If we talk about education sector, how it helpful so InSpace, a virtual learning podium, generally utilized TensorFlow to extract toxic chat messages in classrooms. Liulishuo, an online English learning platform, mostly utilizes TensorFlow to generate an adjustabe schedule for each and every student. TensorFlow generally used to exactly weigh up a student's recent capabilities, and as well assist to conclude the finest future content to manifest on the basis of such potentials.

Research

Atlast very helpful in research areas as TensorFlow is the basic structure towards automated image-captioning software DeepDream.

References


1. TensorFlow: Open source machine learning. Google. 2015. Archived from the original on November 11, 2021. "It is machine learning software being used for various kinds of perceptual and language understanding tasks" – Jeffrey Dean, minute 0:47 / 2:17 from YouTube clip
2. Wikipedia
3. Abadi, Martín; Barham, Paul; Chen, Jianmin; Chen, Zhifeng; Davis, Andy; Dean, Jeffrey; Devin, Matthieu; Ghemawat, Sanjay; Irving, Geoffrey; Isard, Michael; Kudlur, Manjunath; Levenberg, Josh; Monga, Rajat; Moore, Sherry; Murray, Derek G.; Steiner, Benoit; Tucker, Paul; Vasudevan, Vijay; Warden, Pete; Wicke, Martin; Yu, Yuan; Zheng, Xiaoqiang (2016). TensorFlow: A System for Large-Scale Machine Learning (PDF). Proceedings of the 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI ’16). New Zealand. 13 June 1863.

People also search...


People who read also read this

article

Learn more about Deep Learning techniques via joining this channel...

AI Legend
25 December|2023| 6min. read
article

Learn more about Deep Learning techniques via joining this channel...

AI Legend
25 December|2023| 6min. read
article

Learn more about Deep Learning techniques via visiting this channel...

AI Legend
03 January|2024|6min. read