美文网首页
TensorFlow Overview

TensorFlow Overview

作者: 詹徐照 | 来源:发表于2018-11-25 18:00 被阅读24次

Key concept of Machine Learning and TensorFlow

TensorFlow

https://www.tensorflow.org

is an open source machine learning framework.
Support language Python, C++, JavaScript, Java, Go, Swift.

Keras

is a high-level API to build and train models in TensorFlow

Colaboratory

https://colab.research.google.com/notebooks/welcome.ipynb

is a Google research project created to help disseminate machine learning education and research. It's a Jupyter notebook environment that requires no setup to use and runs entirely in the cloud.

Feature and lable

Briefly, feature is input; label is output.
A feature is one column of the data in your input set. For instance, if you're trying to predict the type of pet someone will choose, your input features might include age, home region, family income, etc. The label is the final choice, such as dog, fish, iguana, rock, etc.

Once you've trained your model, you will give it sets of new input containing those features; it will return the predicted "label" (pet type) for that person.
The features of the data, such as a house's size, age, etc.

Classification

Classify things such as classify images of clothing.

Regression

Predict the output of a continuous value according to the input, such as pridict house price according to the features of the house.

Key params for Karas to create a model

  • Layer
  • Loss function —This measures how accurate the model is during training.
  • Optimizer —This is how the model is updated based on the data it sees and its loss - - function.
  • Metrics —Used to monitor the training and testing steps.

Machine Learning Steps

  1. Import dataset.
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
  1. Build model(choose layers, loss function, optimizer, metrics).
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(), 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
  1. Train the model with train dataset, evaluate the trained model with the validate dataset.If not good enough, return to step2.
model.fit(train_images, train_labels, epochs=5)
test_loss, test_acc = model.evaluate(test_images, test_labels)
  1. Use the trained model to classify or predict new input data.
predictions = model.predict(test_images)

Overfitting and underfitting

O

A better understanding of Neural Network

https://playground.tensorflow.org/

image.png

TensorFlow demos

Classification: clissify clothing

import package

# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

import dateset

fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

create model

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(), 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

train model

model.fit(train_images, train_labels, epochs=5)

evaluate accuracy

test_loss, test_acc = model.evaluate(test_images, test_labels)

make predict

predictions = model.predict(test_images)
image

Regression: Predict house price

...

create model

model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu,
                   input_shape=(train_data.shape[1],)),
keras.layers.Dense(64, activation=tf.nn.relu),
keras.layers.Dense(1)
])
optimizer = tf.train.RMSPropOptimizer(0.001)
model.compile(loss='mse',
            optimizer=optimizer,
            metrics=['mae'])

train model

history = model.fit(train_data, train_labels, epochs=EPOCHS,
                    validation_split=0.2, verbose=0,
                    callbacks=[PrintDot()])

相关文章

  • TensorFlow Overview

    Key concept of Machine Learning and TensorFlow TensorFlow...

  • TensorFlow2.0 - C2 Guide - 2 Ker

    1 Keras overview https://www.tensorflow.org/guide/keras建立...

  • markdown测试

    overview overview overview overview hello world overview ...

  • Perception I - Sensors

    Weekly Overview Bookmark this page Overview The learning ...

  • Overview

    This is a story written by Zhang Ailing, about how two in...

  • Overview

    title: Overview Blockly 简介 Blockly是一个库,它为Web和Android应用程序添...

  • Overview

    编程是什么: 在我的眼里,编程是对生产生活的一种抽象,下一层的语言是对上一层的语言的抽象,直到抽象到10,能让计算...

  • Overview

    Java NIO包括以下几个核心的组件: Channels Buffers Selectors Java NIO还...

  • Overview

    In the week 1 video lecture, Dr. Swigart introduces the c...

  • Security Overview

    Security Overview Code Signing Overview: To create a digi...

网友评论

      本文标题:TensorFlow Overview

      本文链接:https://www.haomeiwen.com/subject/websvxtx.html