python停止运行tensorflow_Tensorflow 开启训练后卡死
毕设做深度学习的课题,使用到了TensorFlow,但训练时出现了问题:
跑脚本开启训练之后,跑完不到100次就会卡死,然后显示python已停止工作
这是我的训练的代码
# 导入数据集
import load_record
# 导入TensorFlow并创建Session
import tensorflow as tf
sess = tf.InteractiveSession()
# # 构建计算图
x = tf.placeholder("float", shape = [None, 224, 224, 1])
y_ = tf.placeholder("float", shape = [None, 2])
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape = shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides = [1, 1, 1, 1], padding = 'SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize = [1, 2, 2, 1], strides = [1, 2, 2, 1], padding = 'SAME')
x_image = tf.reshape(x, [-1, 224, 224, 1])
# 第一层卷积
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)
# 第二层卷积
W_conv2 = weight_variable([5, 5, 32, 64])
b_conv2 = bias_variable([64])
h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
h_pool2= max_pool_2x2(h_conv2)
# 第一层全连接层
W_fc1 = weight_variable([56 * 56 * 64, 1024])
b_fc1 = bias_variable([1024])
h_pool2_flat = tf.reshape(h_pool2, [-1, 56*56*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
# Dropout层防止过拟合
keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
# 第二层全连接层输出
W_fc2 = weight_variable([1024, 2])
b_fc2 = bias_variable([2])
y_conv = tf.matmul(h_fc1_drop, W_fc2) + b_fc2
# 训练模型
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.global_variables_initializer())
print('ready...')
for i in range(500):
images, labels = load_record.inputs(data_set = 'train', batch_size = 50, num_epochs = None)
tf.train.start_queue_runners(sess = sess)
_images, _labels = sess.run([images, labels])
if i % 100 == 0:
train_accuracy = accuracy.eval(feed_dict={
x:_images, y_: _labels, keep_prob: 1.0})
print("step %d, training accuracy %g"%(i, train_accuracy))
train_step.run(feed_dict={x: _images, y_: _labels, keep_prob: 0.5})
数据集我是用tfrecord读进去的
def inputs(data_set,batch_size,num_epochs):
if not num_epochs:
num_epochs = None
if data_set == 'train':
file = TRAIN_FILE
else:
file = VALIDATION_FILE
with tf.name_scope('input') as scope:
filename_queue = tf.train.string_input_producer([file], num_epochs=num_epochs)
image,label = read_and_decode(filename_queue)
#随机获得batch_size大小的图像和label
images,labels = tf.train.shuffle_batch([image, label],
batch_size=batch_size,
num_threads=64,
capacity=1000 + 3 * batch_size,
min_after_dequeue=1000
)
return images,labels
求教,如需补充描述请@
只迭代了第一次, 第二次就不行了
python停止运行tensorflow_Tensorflow 开启训练后卡死相关推荐
- python sklearn svm 模型训练后的参数说明
在调用sklearn的SVM时,如果设置verbose=True,模型训练结束后会显示一些训练过程的说明信息,如下(以下是OCSVM的返回结果): * optimization finished, # ...
- Python笔记-解决开启Fiddler后Requests存在SSLError问题
在百度上没有找到合适的答案,都是一些莫名奇妙的设置. 在外网找到了解决的方法,在此记录下,笔记. 不得不说,国外的东西还是香. 分为如下2步: 1. 使用openssl把fiddler的cer证书转为 ...
- keras终止训练后显存不释放_Keras实现Large-scale Bisample Learning on ID vs. Spot Face Recognition...
keras-lbl-IvS 论文地址:Large-scale Bisample Learning on ID vs. Spot Face Recognition 工程地址:keras-lbl-IvS ...
- tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用——模型层次太深,或者太复杂训练时候都不会收敛...
tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用. 数据目录在data,data下放了汉字识别图片: data$ ls 0 1 10 11 12 13 14 1 ...
- tensorflow 模型预训练后的参数restore finetuning
之前训练的网络中有一部分可以用到一个新的网络中,但是不知道存储的参数如何部分恢复到新的网络中,也了解到有许多网络是通过利用一些现有的网络结构,通过finetuning进行改造实现的,因此了解了一下关于 ...
- python 线性回归模型_如何在Python中建立和训练线性和逻辑回归ML模型
python 线性回归模型 Linear regression and logistic regression are two of the most popular machine learning ...
- python打字_使用Python制作一个打字训练小工具
一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. 别人眼中的程序员:飞快的敲击键盘.酷炫的切换屏幕.各种看不懂的字符代码 ...
- python中如何画logistic_如何在 Python 中建立和训练线性和 logistic 回归 ML 模型?
原标题:如何在 Python 中建立和训练线性和 logistic 回归 ML 模型? 英语原文: 翻译:(Key.君思) 线性回归与logistic回归,是. 在我的里,你们已经学习了线性回归机器学 ...
- 判赔20万!星愿浏览器因拦截广告被优酷起诉;苹果调查iPhone 14 Pro传输数据后卡死问题|极客头条...
「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧. 整理 | 梦依丹 出品 | CSDN(ID:CSDNnews ...
最新文章
- 携程数据库高可用架构实践
- SharePoint 列表应用实例 - 显示约束
- (转载)VS2010/MFC编程入门之五十四(Ribbon界面开发:使用更多控件并为控件添加消息处理函数)...
- Django的视图层简介
- [Ext JS]12.12.1 必填字段组件扩展
- 影响机器视觉光源效果的因素有哪些?
- python读excel并写入_Python 写入和读取Excel数据
- 【转】MEF程序设计指南四:使用MEF声明导出(Exports)与导入(Imports)
- 跟着鬼哥学爬虫-2-糗事百科
- bt种子磁力播放器 android,(安卓)种子磁力在线播放器 — 可离线至本地
- ActiveMQ下载、安装、启动
- 共享单车调度_共享单车的调度算法
- 怎么获取淘宝商品详情
- 今日学习在线编程题:幻数
- 打造自己个性的notepad ++
- 计算机启动进入不了桌面图标,电脑开机后,进到桌面图标都没有开始也点不开 win10...
- 精力管理-健康生活 高效工作
- [费用流] LOJ#545. 「LibreOJ β Round #7」小埋与游乐场
- 预警html效果,预警电子邮件 HTML 模板的语法
- python 常用库简介