基于 tensorflow2.0 的人工智能、机器学习和深度学习简介和基础编程

因为已经比较熟悉了,所以记录得非常简单。

1.1 Introduction - A conversation with Andrew Ng

主讲:Laurence Moroney

Learn how to code in TensorFlow and the difference between traditional programming paradigms versus the machine learning and deep learning programming paradigms.

1.2 A primer in machine learning

Traditional Programming VS Machine Learning


给定一堆我们平时见到的样例(answes),让 machine 去寻找其中的 rules。
人为设定较为完善的规则很难,比如走路、跑步、骑车,甚至打高尔夫细节很多,各有差异。但是可以给 machine 很多例子,给定 answer,让 machine 寻找其中的 rules。

1.3 The ‘Hello World’ of neural networks

核心:machine 在模仿人,看到两个变量关系时,试图 guess,guess 答案之后,再看看 guess 得怎么样,逐步迭代。

model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')xs = np.array([], dtype=float])
ys = np.array([], dtype=float)model.fit(xs, ys, epoch=500)print(model.predict([10.0]))

这里,结果接近标准答案,但并不一定会是标准答案:

  • 训练数据很少;
  • 神经网络按照概率来输出预测。

1.4 Working through ‘Hello World’ in Tensorflow and Python

使用的 Googlo Colab,需要科学上网。

loss 会越来越小。

2.1 Conversation with Andrew Ng

神经网络处理直线是 ‘Hello World,下面仍然沿用上面整体的流程模板,使用图像数据集,来完成 computer vision 的任务。

2.2 An introduction to computer vision

数据集:

  • Fashion MNIST
  • 70k Images
  • 10 Categories
  • Images are 28 × 28
  • Can train a neural net!
  • binary 0 or 255
  • single image’size is 28 × 28 bytes
  • 在 tensorflow 中有 dataset api

2.3 Writing code to load training data

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

2.4 Coding a Computer Vision Neural Network

定义模型结构

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)
])

2.5 Working through a Notebook for computer vision

检查数据

import matplotlib.pyplot as plt
plt.imshow(training_image[0])
print(training_labels[0])
print(trainig_images[0])

数据标准化

traing_images = traning_images / 255.0
test_images = test_images / 255.0

编译、训练和评估

model.compile(optimizer=tf.train.AdamOptimizer(),
# 无需对 label 进行 one-hot 编码
loss='sparse_categorical_crossentropy')model.fit(training_images, training_labels, epochs=5)model.evaluate(test_images, test_labels)

2.6 Using Callbacks to control training

如何停止训练:使用 callbacks。

Class myCallback(tf.ketas.callbacks.Callback):def on_epoch_end(self, epoch, logs={}):if(logs.get('loss')<0.4):print("\nLoss is low so cancelling training!")self.model.stop_traing = Truecallbacks = myCallback()
model.fit(training+images, training_labels, epochs=5, callbacks=[callbacks])

2.7 Work through a notebook with Callbacks

3.1 Conversation with Andrew Ng

增加卷积处理。

3.2 What are convolutions and pooling

即使图片被缩放到 28 × 28,已经相对很小了,但是有没有可能再将其压缩成一些重要的特征。
卷积核就是滤波器,根据卷积核中的参数,可以提取原图中不同的特征,比如不同方向的边缘等。

3.3 Implementing convolutional layers

model = tf.keras.models.Sequential([tf.keras.layers.Conv2D(64, (3, 3), activation='relu', input_shape=(28, 28, 1)),tf.keras.layers.MaxPooling2D(2, 2),tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),tf.keras.layers.MaxPooling2D(2, 2),tf.keras.layers.Flatten(),tf.keras.layers.Dense(128, activation='relu'),tf.karas.layers.Dense(10, activation='softmax')
])

3.4 Implementing pooling layers

卷积层和池化层都可以起到简化信息/特征的作用,通过 model.summary() 可以查看模型中每层的变化。

3.5 Improving the Fashion classfier with convolutions

可视化

import matplotlib.pyplot as plt
f, axarr = plt.subplot(3, 4)
FIRST_IMAGE = 0
SECONDE_IMAGE = 23
THIRD_IMAGE = 28CONVOLUTION_NUMBER = 1
from tensorflow.keras import models
layer_outputs = [layer.output for layer in model.layers]activation_model = tf.keras.models.Model(input=model.input, output=layer_output)for x in range(0, 4):f1 = activation_model.predict(test_image[FIRST_IMAGE].reshape(1, 28, 28, 1))[x]axarr[0, x].imshoW(f1[0, :, :, CONVOLUTION_NUMBER], cmap='inferno')axarr[0, x].grid(False)f2 = activation_model.predict(test_image[SECOND_IMAGE].reshape(1, 28, 28, 1))[x]axarr[1, x].imshoW(f2[0, :, :, CONVOLUTION_NUMBER], cmap='inferno')axarr[1, x].grid(False)f3 = activation_model.predict(test_image[THIRD_IMAGE].reshape(1, 28, 28, 1))[x]axarr[2, x].imshoW(f3[0, :, :, CONVOLUTION_NUMBER], cmap='inferno')axarr[2, x].grid(False)

3.6 Walking through convolutions

卷积基本操作。

4.1 A conversation with Andrew Ng

4.2 Understanding ImageGenerator

API for 生成训练数据。

from tensorflow.keras.preprocessing.image
import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale=1./255)# 从目录生成训练数据,子目录的名字就是其内图片的 label
train_generator = train_datagen.flow_from_directory(train_dir,target_size=(300, 300),batch_size=128,class_mode='binary'
)test_datagen = ImageDataGenerator(rescale=1./255)# 从目录生成训练数据,子目录的名字就是其内图片的 label
validation_generator = test_datagen.flow_from_directory(validation_dir,target_size=(300, 300),batch_size=32,class_mode='binary'
)

4.3 Defining a ConvNet to use complex images

  • 输入 300 × 300
  • 3 层卷积 + 3 层池化
  • 最后输出一个神经元,激活用 sigmoid,来处理二分类问题;
  • 也可以用两个神经元,激活用 softmax,不过效率低一点。

参数量:

  • (3 × 3 × 3 + 1) × 16 = 448
  • (3 × 3 × 16 + 1) × 32 = 4640
  • (3 × 3 × 32 + 1) × 64 = 18496
  • (78400 + 1) × 512 = 40,141,312
  • (512 + 1) × 1 = 513

model = tf.keras.models.Sequential([tf.keras.layers.Conv2D(16, (3, 3), activation='relu', input_shape=(300, 300, 3)),tf.keras.layers.MaxPooling2D(2, 2),tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),tf.keras.layers.MaxPooling2D(2, 2),tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),tf.keras.layers.MaxPooling2D(2, 2),tf.keras.layers.Flatten(),tf.keras.layers.Dense(512, activation='relu'),tf.karas.layers.Dense(1, activation='sigmoid')
])

4.4 Training the ConvNet with fit_generator

# RMSprop 可以调整学习率
from tensorflow.keras.optimizers import RMSprop# 因为现在是二分类,所以不再用多分类的 categorical_crossentropy,而是使用 binary_crossentropy
model.compile(loss='binary_crossentropy', optimizer=RMSprop(lr=0.001), metrics=['acc'])# 对应数据使用 generator,fit 这里也是用 generator
history = model.fit_generator(train_generator, steps_per_epoch=8, # 根据数据集大小和 batchsize 计算的epochs=15,validation_data=validation_generator,validation_steps=8,   # 根据数据集大小和 batchsize 计算的verbose=2)

4.5 Walking through developing a ConvNet

4.6 Walking through training the ConvNet with fit_generator

4.7 Adding antomatic validation to test accuracy

4.8 Exploring the impact of compressing images

数据不能过度压缩或者减量,会过拟合(相比来讲就是模型参数变多了)。

吴恩达 tensorflow2.0 实践系列课程(1):基础相关推荐

  1. 吴恩达 tensorflow2.0 实践系列课程(3):NLP

    tensorflow2.0 中的自然语言处理 基本都是入门级的,而且也正如课程设计目标,主体放在 tensorflow 的基本使用上.围绕的 NLP 相关问题有: 文本如何变为数字送入模型进行处理? ...

  2. 就在刚刚!吴恩达的这门新课程终于开放注册了

    点击上方"AI有道",选择"星标"公众号 重磅干货,第一时间送达 相信我的很多读者都学习过吴恩达在 Coursera 上开设的 <Machine Lear ...

  3. 吴恩达deeplearning.ai五项课程完整笔记了解一下?

    来源:机器之心 本文共3744字,建议阅读8分钟. 通过本文为大家解读如何构建自然语言.音频和其他序列数据的模型. 自吴恩达发布 deeplearning.ai 课程以来,很多学习者陆续完成了所有专项 ...

  4. Coursera吴恩达《深度学习》课程总结(全)

    这里有Coursera吴恩达<深度学习>课程的完整学习笔记,一共5门课:<神经网络和深度学习>.<改善深层神经网络>.<结构化机器学习项目>.<卷 ...

  5. 吴恩达的TensorFlow实践课上线,有Python基础就能听,4个月学完

    晓查 发自 凹非寺 量子位 出品 | 公众号 QbitAI 吴恩达的deeplearning.ai上新了!新的AI课程叫做TensorFlow in Practice,面向那些希望学习使用Tensor ...

  6. Coursera吴恩达《序列模型》课程笔记(2)-- NLP Word Embeddings

    红色石头的个人网站:redstonewill.com <Recurrent Neural Networks>是Andrw Ng深度学习专项课程中的第五门课,也是最后一门课.这门课主要介绍循 ...

  7. 新建网站了!Github标星过万的吴恩达机器学习、深度学习课程笔记,《统计学习方法》代码实现,可以在线阅读了!...

    吴恩达机器学习.深度学习,李航老师<统计学习方法>,可以说是机器学习入门的宝典.本文推荐一个网站"机器学习初学者",把以上资源的笔记.代码实现做成了网页版,可以在线阅读 ...

  8. 吴恩达deeplearning.ai深度学习课程空白作业

      吴恩达deeplearning.ai深度学习课程的空白作业,包括深度学习微专业五门课程的全部空白编程作业,经多方整理而来.网上找来的作业好多都是已经被别人写过的,不便于自己练习,而且很多都缺失各种 ...

  9. 马斯克称自己不喜欢做CEO,更想做技术和设计;吴恩达的《机器学习》课程即将关闭注册|极客头条

    「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧. 整理 | 梦依丹 出品 | CSDN(ID:CSDNnews ...

最新文章

  1. 计算机一级考试模拟题函数,2015年计算机一级考试模拟题(四)
  2. 【HDU/算法】最短路问题 杭电OJ 2544 (Dijkstra,Dijkstra+priority_queue,Floyd,Bellman_ford,SPFA)
  3. Delphi组件开发-在窗体标题栏添加按钮
  4. PHP 数组遍历 foreach 语法结构
  5. 多久能学会前端?怎么学?
  6. onmousemove和onmouseout事件的调用,和js使用双引号、单引号的时候应该注意的问题...
  7. python list 底层_深入Python列表的内部实现
  8. 10个前端开发人员必须知道的CSS框架
  9. 算法“视”界杯上演十强争锋,大赛终极一战圆满落幕
  10. 信贷违约风险预测(一)样本数据
  11. 分享110个采集小偷PHP源码,总有一款适合你
  12. SoapUI接口测试——关联——参数化
  13. 【RemoteJoy】PSP图像采集方案
  14. 苹果手机屏幕镜像_微软应用上线屏幕镜像功能:可在PC端控制安卓手机
  15. 跑马灯(走马灯)的js实现
  16. 关于java爬虫手机壁纸图片网站
  17. WORD里的拼页、书籍折页、反向书籍折页功能(一)
  18. 调试技巧:如何以数组的方式查看一个指针
  19. python 识别人名_HanLP中人名识别分析
  20. 走进Vue.js 1.0-姜威-专题视频课程

热门文章

  1. 你把我折磨的好惨,不用质疑说的就是你
  2. 企业中常见的审批流程
  3. ping www.baidu.com 中的 TTL值 及其他参数的理解
  4. vlc android 源码分析,Vlc-for-android源码分析
  5. php将网页内容存到word,php在程序中将网页生成word文档并提供下载的代码
  6. 中消协提醒市民门锁防盗升级 玥玛锁响应号召普及锁具知识
  7. 网站前端优化一些小经验
  8. 基于Duilib的多标签浏览器(IE内核)
  9. eclipse adt with the android sdk for windows,关于Windows:Eclipse:不允许我使用Android SDK,错误地声称我的ADT已过时...
  10. Linux读取windows光盘,如何从Windows,Mac和Linux上的光盘创建ISO文件