tensorflow2.0学习(一)

环境配置我就不再这赘述了

1利用kares搭建分类模型

import tensorflow as tf
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import sklearn
import pandas as pd
import os
import sys
import time
from tensorlow import keras

print(tf.__version__)
print(sys.version_info)
for module in mpl,np,pd,sklearn,tf,keras:
    print(module.__name__, module.__version__)

%%加载训练集和测试集
fashion_mnist = keras.datasets.fashion_mnist
(x_train_all,y_train_all),(x_test,y_test) = fashion_mnist.load_data()
x_vaild,x_train = x_train_all[:5000],x_train_all[5000:]
y_vaild,y_train = y_train_all[:5000],y_train_all[5000:]
print(x_vaild.shape,y_vaild.shape)
print(x_train.shape,y_train.shape)
print(x_test.shape,y_test.shape)

def show_single_iamge(image_arr):
    plt.imshow(img_arr,cmap ="binary")
    plt.show()
show_single_image(x_train[0])

model = keras.model.Sequential()
modle.add(keras.layers.Flatten(input_shape[28,28]))
model.add(keras.layers.dense(300,activation="relu"))
model.add(keras.layers.dense(100,activation="relu"))
model.add(keras.layers.dense(10,activetion="softmax"))

model.compile(loss ="sparse_categorical_crossentropy",optimizer ="sgd",metrics = ["accuracy"])
%查看层
model.layers

model.summary



 

1.1激活函数:

relu:

y=max(1,x)

softmax:

将向量变成概率分布。

x=[x1,x2,x3]

y=[e^x1/sum,e^x2/sum,[e^x3/sum] ;  (sum = e^x1+e^x2+e^x3)

1.2全连接层参数计算

假设输入为x:[28,28]=784

x*w+b=>w.shape = [784,300], b.shape = [300]

总的参数数量 = w.shape + b.shape

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值