MachineLearning_Google_Tensorflow

1 篇文章 0 订阅

Machine Learning

-tensorflow

–环境

编辑器上安装:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu
国内镜像
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
华为:https://repo.huaweicloud.com/repository/pypi/simple

使用免费线上资源,免费CPU,GPU
Colab
Kaggle
kaggle使用时的小细节

文件压缩包的下载和解压

!wget --no-check-certificate \
http://storage.googleapis.com/laurencemoroney-blog.appspot.com/validation-horse-or-human.zip \
-O /tmp/validation-horse-or-human.zip

!wget --no-check-certificate \
http://storage.googleapis.com/laurencemoroney-blog.appspot.com/horse-or-human.zip \
-O /tmp/horse-or-human.zip

import zipfile
train = zipfile.ZipFile("/tmp/horse-or-human.zip")
train.extractall(path="/tmp/horse-or-human")
validation = zipfile.ZipFile("/tmp/validation-horse-or-human.zip")
validation.extractall(path="/tmp/validation-horse-or-human")

kaggle的详细目录结果,_注意_并非只有working和input目录,并且kaggle也不是根目录,只是一个子目录

在这里插入图片描述

–基础程序结构

下列小总结大部分来源于------Google官方TensorFlow系列视频

import tensorflow as tf

##载入数据
data_x = []
data_y = []

##模型建立
model = tf.keras.Sequential()
model.add()

##优化
model.compile(loss= '', optimizer='')

##训练
model.fit(data_x, data_y, epochs = )

–构建神经元模型

#构造神经元模型
    model = keras.Sequential([
    keras.layers.Flatten(input_shape= (28,28)),#输入层
    keras.layers.Dense(128,activation=tf.nn.relu),#中间层,128个神经元
    keras.layers.Dense(10, activation = tf.nn.softmax)#输出层,10个神经元
])

模型示意图

在这里插入图片描述

relu函数和softmax函数

在这里插入图片描述

过拟合(overfitting)

由于训练次数过多,导致训练的loss出现如下变化

在这里插入图片描述

因此可使用callbacks进行处理,当满足需要的精度后,就跳出训练

在这里插入图片描述

在拟合某些非线性模型(此处主要指二次曲线,三次曲线等等)

目前可以得出,通过调整神经元的数量units,激活函数activation,以及层数layers,最主要是训练素材的数量,
以下便是一个训练的草图
在这里插入图片描述

–CNN(convolutional neural network)

convolution and pooling
convolution

过滤器中的数值与像素对应位置相乘

2,3图分别为着重提取纵向与横向特征
其过滤器如下

#  filter = [[-1, -2, -1],[0, 0, 0],[1, 2, 1]]
#  filter = [[-1, 0 ,1],[-2, 0, 2],[-1, 0, 1]]

下面便是分别是原图,提取纵向,提取横向,池化的结果
在这里插入图片描述

pooling

Max pooling 增强特征,减少数据

–图像增强

此操作可以避免由于数据量不够,而引起的过拟合

# 此操作可以避免由于数据量不够,而引起的过拟合
# train_datagen = ImageDataGenerator(
#         rescale = 1./255,   统一图像尺寸
#         rotation_range=40,   随机旋转每个图像,图像角度 -40度~40度
#         width_shift_range=0.2,       width与height让图像在画框中,安装设定的范围平移
#         height_shift_range=0.2,     此处,图像对多平移宽度或高度的20%
#         shear_range=0.2,      值为0~1,最多可以剪切图像的20%
#         zoom_range=0.2,       值为0~1,提供0~20%的范围随机放大
#         horizontal_flip = True,   图像将被随机翻转
#         fill_mode = 'nearest'     补全图像在操作中的丢失部分,比如倾斜后超出原图的像素
            
# )

未完,待续、、、
均为个人见解,勿喷、、、

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

taco_HUA_James

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值