tensorflow

毕业设计之「测试实验及结果分析」(一)

人盡茶涼 提交于 2021-01-05 23:50:36
阅读本文大概需要 18 分钟。 前言 在毕设系列推文的第二章中我们详细介绍了TensorFlow的一些基础知识( TensorFlow 2.0 概述 );在第三章( 毕业设计之「神经网络与深度学习概述」 (一) 、 毕业设计之「神经网络与深度学习概述」(二) )中对神经网络与深度学习做了简单的概述(主要介绍本章节中完成两个项目所用的一些基础概念)包括激活函数、梯度下降、损失函数、softmax算法等;并且通过简单描述全连接神经网络的不足,详细介绍了卷积神经网络的相关概念。 有了前面几章的基础知识,在本章中,我们会在此基础上介绍两个相关的例子(在此之前会对4.1节中对所用卷积神经网络 AlexNet 进行详尽的描述): 其中包括 利用AlexNet完成MNIST手写字的训练和识别 (本文所涉及内容)以及 毕业设计之「测试实验及结果分析」(二) 。 第一个例子是论文中要求指定完成的例子;第二个例子是为了丰富论文成果通过Python爬虫技术收集数据样本集(包括测试集图片和训练集图片,共计3762张图片)、通过搭建AlexNet标准网络结构模型进行训练,并通过测试集图片进行最终结果分析而特别引入的。 图解AlexNet网络结构 MNIST手写字训练和识别 import TensorFlow as tf mnist = tf.keras.datasets.mnist (x_train, y

How to load a keras model saved as .pb

时间秒杀一切 提交于 2021-01-05 13:24:47
问题 I'd like to load a keras model that i've trained and saved it as .pb . Here's the code, Am using a jupyter notebook. The model is successfully saved as saved_model.pb under the same directory. But the code is unable to access it. Can anybody see to it, how can i access this keras model that's saved in .pb extension. I checked at several other places for solution but no luck. Model is saved at model/saved_model.pb . I've taken out the .pb file and placed it in the same directory where my code

Resource exhausted: OOM when allocating tensor only on gpu

不打扰是莪最后的温柔 提交于 2021-01-05 13:04:04
问题 I'm trying to run several different ML architectures, all vanilla, without any modification ( git clone -> python train.py ). while the result is always the same- segmentation fault , or Resource exhausted: OOM when allocating tensor. When running only on my CPU, the program finishes successfully I'm running the session with config.gpu_options.per_process_gpu_memory_fraction=0.33 config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = True And

Loss: NaN in Keras while performing regression

天大地大妈咪最大 提交于 2021-01-05 11:34:32
问题 I am trying to predict a continuous value (using a Neural Network for the first time). I have normalized the input data. I can't figure out why I am getting a loss: nan output starting with the first epoch. I read and tried many suggestions from previous answers to the same question but that none of them helped me. My training data shape is: (201917, 64) . Here's my code: model = Sequential() model.add(Dense(100, input_dim=X.shape[1], activation='relu')) model.add(Dense(100, activation='relu'

My deep learning model is not training. How do I make it train?

∥☆過路亽.° 提交于 2021-01-05 09:10:45
问题 I'm fairly new to Keras, please excuse me if I made a fundamental error. So, my model has 3 Convolutional (2D) layers and 4 Dense Layers, interspersed with Dropout Layers. I am trying to train a Regression Model using images. X_train.shape = (5164, 160, 320, 3) y_train.shape = (5164) from tensorflow.keras import Sequential from tensorflow.keras.layers import Dense, Flatten, Conv2D, Activation, MaxPooling2D, Dropout import tensorflow.compat.v1 as tf tf.disable_v2_behavior() from tensorflow

My deep learning model is not training. How do I make it train?

社会主义新天地 提交于 2021-01-05 09:09:16
问题 I'm fairly new to Keras, please excuse me if I made a fundamental error. So, my model has 3 Convolutional (2D) layers and 4 Dense Layers, interspersed with Dropout Layers. I am trying to train a Regression Model using images. X_train.shape = (5164, 160, 320, 3) y_train.shape = (5164) from tensorflow.keras import Sequential from tensorflow.keras.layers import Dense, Flatten, Conv2D, Activation, MaxPooling2D, Dropout import tensorflow.compat.v1 as tf tf.disable_v2_behavior() from tensorflow

TensorFlow——学习率衰减的使用方法

徘徊边缘 提交于 2021-01-05 08:38:31
在TensorFlow的优化器中, 都要设置学习率。学习率是在精度和速度之间找到一个平衡: 学习率太大,训练的速度会有提升,但是结果的精度不够,而且还可能导致不能收敛出现震荡的情况。 学习率太小,精度会有所提升,但是训练的速度慢,耗费较多的时间。 因而我们可以使用退化学习率,又称为衰减学习率。它的作用是在训练的过程中,对学习率的值进行衰减,训练到达一定程度后,使用小的学习率来提高精度。 在TensorFlow中的方法如下:tf.train.exponential_decay(),该方法的参数如下: learning_rate, 初始的学习率的值 global_step, 迭代步数变量 decay_steps, 带迭代多少次进行衰减 decay_rate, 迭代decay_steps次衰减的值 staircase=False, 默认为False,为True则不衰减 例如 tf.train.exponential_decay(initial_learning_rate, global_step=global_step, decay_steps=1000, decay_rate=0.9)表示没经过1000次的迭代,学习率变为原来的0.9。 增大批次处理样本的数量也可以起到退化学习率的作用。 下面我们写了一个例子,每迭代10次,则较小为原来的0.5,代码如下: import

tensorflow之tf.train.exponential_decay()指数衰减法

社会主义新天地 提交于 2021-01-05 08:22:28
exponential_decay(learning_rate, global_steps, decay_steps, decay_rate, staircase=False, name=None) 使用方式: tf.tf.train.exponential_decay() 例子: tf.train.exponential_decay(self.config.e_lr, self.e_global_steps,self.config.decay_steps, self.config.decay_rate, staircase=True) 在 Tensorflow 中,exponential_decay()是应用于学习率的指数衰减函数(实现指数衰减学习率)。 在训练模型时,通常建议随着训练的进行逐步降低学习率。该函数需要`global_step`值来计算衰减的学习速率。 该函数返回衰减后的学习率。该函数的计算方程式如下 参数: learning_rate - 初始学习率 global_step - 用于衰减计算的全局步骤。 一定不为负数。喂入一次 BACTH_SIZE 计为一次 global_step decay_steps - 衰减速度,一定不能为负数,每间隔decay_steps次更新一次learning_rate值 decay_rate - 衰减系数,衰减速率

trying to pickle ML model can't pickle _thread.RLock objects in google colab

≯℡__Kan透↙ 提交于 2021-01-05 07:45:52
问题 I am training a MNIST dataset using CNN in google colab and want to save the model using pickle and when i try saving the model I get the error can't pickle _thread.RLock objects My Code import pickle import numpy as np import tensorflow as tf import matplotlib.pyplot as plt import keras from keras.datasets import mnist from keras.utils import to_categorical from keras.models import Sequential from keras.layers import Conv2D , MaxPooling2D, Dense, Flatten,Dropout from keras.optimizers import

trying to pickle ML model can't pickle _thread.RLock objects in google colab

假如想象 提交于 2021-01-05 07:45:30
问题 I am training a MNIST dataset using CNN in google colab and want to save the model using pickle and when i try saving the model I get the error can't pickle _thread.RLock objects My Code import pickle import numpy as np import tensorflow as tf import matplotlib.pyplot as plt import keras from keras.datasets import mnist from keras.utils import to_categorical from keras.models import Sequential from keras.layers import Conv2D , MaxPooling2D, Dense, Flatten,Dropout from keras.optimizers import