本任务为分类分类属性的8个类别。 dict_gender = {'f':0, 'm':1 } dict_age = {'children':0, 'young':1, 'adult':2, 'older':3 } 用的keras的datagen_train.flow_from_directory。 train_generator=datagen_train.flow_from_direc
业余时间学习下深度学习,个人理解就是对已有的数据进行非线性映射,然后再映射的空间内找出数据的特征(个人理解可能不准,请指正)。 源码地址:https://github.com/yu-bo/stock 然后想着找一些数据练习下,网上的教程例子很多,个人想着预测下股票信息,大概的过程如下: 1、使用tushare获取sto
我们使用的数据集为tesnflow2自带的的电影评论数据集imdb 加载数据集,第一次加载的时候可能要到外网下载数据,比较慢,我放在网盘里,下载链接:https://pan.baidu.com/s/1tq_kO3tlDmwn-CMTCBrpLw 提取码:4r7f 下载后将其拷贝到 data = keras.datasets.imdb #限定读取的单词个数 max_w
文章目录TensorFlow2学习——图像分类导包原始数据数据作图数据划分与标准化构建模型并训练模型评估与预测其他:回调Callback的使用 TensorFlow2学习——图像分类 导包 import matplotlib.pyplot as plt import numpy as np import pandas as pd import tensorflow as tf fro
《Densely Connected Convolutional Networks》提出了DenseNet,它用前馈的方式连接每一层与所有其他层,网络的核心结构为如下所示的Dense块,在每一个Dense块中,存在多个Dense层,即下图所示的H1~H4。各Dense层之间彼此均相互连接。 不一定需要在Dense块中对每一个Dense层均直接进
实例:1 + 1/2 + 1/2^2 + 1/2^3 + … + 1/2^50 tensorflow1 导包,看版本 import tensorflow as tf print(tf.__version__) 定义变量 x = tf.Variable(0.) y = tf.Variable(1.) 定义计算图 # x = x + y add_op = x.assign(x + y) # y = y / 2 div_op = y.assign(y / 2)
1、度娘了“@autograph.convert()” 的相关内容,这应该是 20180719 Google除的新功能,大概的功能是: “谷歌发布AutoGraph,自动将Python转化为TF图” “AutoGraph:图的简易控制流程” 等 ZC:搜索到的文章 都只是说出了 新的功能,但是没说 是 版本1 还是 版本2 里面的功
以下代码利用tensorflow2.1中的keras API做了一个简单的模型(简单到输入层和输出层都只有一个神经元),利用这个模型学习出y=2x+2的规律。 from tensorflow import keras model=keras.Sequential([keras.layers.Dense(units=1,input_shape=[1])]) model.compile(optimizer='sg
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himmeblau(x): return (x[0]**2 + x[1] - 11)**2 + (x[0] + x[1]**2 - 7)**2 x = np.arange(-6, 6, 0.1) y = np.arange(-6, 6, 0.1) print(f'x_shape: {x.shap
import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch(a) y = tf.sigmoid(a) grads = tape.gradient(y, [a]) grads a = tf.linspace(-5.,5.,10) a tf.tanh(a)
import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as tape: tape.watch([w]) y2 = x * w grad1 = tape.gradient(y, [w]) grad1 with tf.GradientTape() as tape: tape.watch([w]) y2 = x * w
import tensorflow as tf y = tf.constant([1, 2, 3, 0, 2]) y = tf.one_hot(y, depth=4) # max_label=3种 y = tf.cast(y, dtype=tf.float32) out = tf.random.normal([5, 4]) out loss1 = tf.reduce_mean(tf.square(y - out)) loss1 loss2 = tf.square(tf.norm(y - ou
sigmoid out' = sigmoid(out) # 把输出值压缩在0-1 import tensorflow as tf a = tf.linspace(-6., 6, 10) a tf.sigmoid(a) x = tf.random.normal([1, 28, 28]) * 5 tf.reduce_min(x), tf.reduce_max(x) x = tf.sigmoid(x) tf.reduce_min(x), tf.reduce_max(x) a
import tensorflow as tffrom tensorflow import keras# train: 60k | test: 10k(x, y), (x_test, y_test) = keras.datasets.mnist.load_data()x.shapey.shape # 0纯黑、255纯白x.min(), x.max(), x.mean() x_test.shape, y_test.shape # 0-9有10种分类结果y_onehot = tf.
import tensorflow as tfa = tf.random.shuffle(tf.range(5))a tf.sort(a, direction='DESCENDING') # 返回索引tf.argsort(a, direction='DESCENDING') idx = tf.argsort(a, direction='DESCENDING')tf.gather(a, idx) idx = tf.argsort(a
手写数字识别流程MNIST手写数字集7000*10张图片60k张图片训练,10k张图片测试每张图片是28*28,如果是彩色图片是28*28*30-255表示图片的灰度值,0表示纯白,255表示纯黑打平28*28的矩阵,得到28*28=784的向量对于b张图片得到[b,784];然后对于b张图片可以给定编码把上述的普通编码给定成独
本实验使用了mnist.npz数据集,可以使用在线方式导入,但是我在下载过程中老是因为网络原因被打断,因此使用离线方式导入,离线包已传至github方便大家下载: https://github.com/guangfuhao/Deeplearning/blob/master/mnist.npz (mnist.npz下载)
线性回归 #建立模型结构model = tf.keras.Sequential()#添加层,第一个参数是输出神经元个数,第二个参数表示(输入特征,输入训练数量)model.add(tf.keras.layers.Dense(1,input_shape=(1,)))#查看网络层结构model.summary() #编译,参数分别是优化方法,损失函数model.compile(optimizer=
1.导入数据 num_words = 30000 maxlen = 200 (x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=num_words) print(x_train.shape, ' ', y_train.shape) print(x_test.shape, ' ', y_test.shape) x_train = ker
直接运行: pip install tensorflow==2.0.0b1 -i https://pypi.tuna.tsinghua.edu.cn/simple 报错1: tb-nightly 1.14.0a20190603 has requirement setuptools>=41.0.0, but you'll have setuptools 39.0.1 which is incompatible. setuptools版本过低,需要先更新, pip install -
目录 TensorFlow2-创建 Tensor numpy, list numpy list zeros, ones, fill zeros ones fill random 打乱idx后,a和b的索引不变 constant loss计算 无bias的loss TensorFlow2-创建 Tensor * from numpy, list * zeros, ones, fill * random # if big dimension, random in