Tensorflow 报错 Process finished with exit code 3

  • Process finished with exit code 3

最近在跟着B站视频 视频网址 学习Tensorflow框架,在学习到CNN的时候,跟着视频写的程序,出错,显示“Process finished with exit code 3”,网上百度,答案也很少。后来自己仔细查找了下原因,发现出现“Process finished with exit code 3”问题的原因是因为内存不够。第一次运行的时候是将程序在台式电脑上面运行,一直报错,跑不出来。后来将程序放到服务器上面,设置train的大小。并可以成功运行,经过试验测试得到,Train的最大值为37853,一旦超过这个数据,程序便会报错。因为我使用的服务器是一块显卡,运行内存只有8G,等下次将服务器更改为两块显卡16G内存的时候,我再来更新。

程序代码附下:

# _*_ coding:utf-8 _*_
# 开发人员 : lenovo
#开发时间 :2019/6/1511:43
# 文件名称 :CNN1 06-2.py
# 开发工具 : PyCharm#卷积神经网络应用于MNIST数据集分类#import os
import tensorflow as tf
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets('MNIST_data',one_hot= True)#如果读取不出来,就自己手动将数据集写入到对应文件夹里面#每个批次大小
batch_size = 100#计算一共有多少个批次
n_batch = mnist.train.num_examples // batch_size
#print("mnist.train.num_examples :",mnist.train.num_examples )#初始化权值
def weight_variable(shape):inital = tf.truncated_normal(shape,stddev=0.1)  #生成一个截断的正态分布return tf.Variable(inital)#初始化偏置
def bias_variable(shape):inital = tf.constant(0.1,shape=shape)return tf.Variable(inital)#卷积层
def conv2d(x,W):# x 指输入;W 指CNN的卷积核;strides 卷积时在图像上每一维的步长,一般首尾(0,3位)为1,中间为自定义的步长(中间第一位代表x方向的步长,第二个代表y方向的歩长)return tf.nn.conv2d(x,W,strides=[1,1,1,1],padding='SAME')  # 还有一种是VALID(不会补0)  SAME会补0#池化层
def max_pool_2x2(x):return tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')#   ksize=[1,2,2,1] 第0 3位必须是1,中间两位分别代表x,y方向的窗口的大小#定义两个placeholder
with tf.name_scope('input'):x = tf.placeholder(tf.float32, [None, 784],name='x_input')  # none行,28*28 784列y = tf.placeholder(tf.float32, [None, 10],name='y_input')with tf.name_scope('input'):# 改变x的格式转为4D的向量[batch,in_height,in_width,in_channels]x_image = tf.reshape(x, [-1, 28, 28, 1],name='x_image')  # -1表示批次,第二个代表长,第三个代表宽,1代表一维黑白,如果是彩色,则是3#初始化第一个卷积层的权值和偏置
with tf.name_scope('Conv1'):with tf.name_scope('W_conv1'):W_convl = weight_variable([5, 5, 1, 32])  # 5*5的采样窗口,1表示黑白,32个卷积核从1个平面抽取特征with tf.name_scope('b_conv1'):b_convl = bias_variable([32])  # 每一个卷积核一个偏置with tf.name_scope('relu'):relu = conv2d(x_image,W_convl)+b_convlwith tf.name_scope('h_conv1'):# 把X_image和权值向量进行卷积,再加上偏置值,然后应用于relu激活函数h_conv1 = tf.nn.relu(relu)with tf.name_scope('h_pool1'):h_pool1 = max_pool_2x2(h_conv1)  # 进行max_pooling#初始化第二个卷积层的权值和偏置
with tf.name_scope('Conv2'):with tf.name_scope('W_conv2'):W_conv2 = weight_variable([5, 5, 32, 64])  # 5*5的采样窗口,64个卷积核从32个平面抽取特征with tf.name_scope('b_conv2'):b_conv2 = bias_variable([64])  # 每一个卷积核一个偏置# 把X_image和权值向量进行卷积,再加上偏置值,然后应用于relu激活函数with tf.name_scope('relu2'):relu2 = conv2d(h_pool1,W_conv2)+b_conv2with tf.name_scope('h_conv2'):h_conv2 = tf.nn.relu(relu2)with tf.name_scope('h_pool2'):h_pool2= max_pool_2x2(h_conv2)  #进行max_pooling#28*28的图片第一次卷积后还是28*28,第一次池化后变成14*14
#第二次卷积之后为14*14,第二次池化后为7*7
#经过上面操作后得到64*64张7*7的平面#初始化第一个全连接的权值
with tf.name_scope('fc1'):with tf.name_scope('W_fc1'):W_fc1 = weight_variable([7 * 7 * 64, 1024])with tf.name_scope('b_fc1'):b_fc1 = bias_variable([1024])#把池化层2的输出扁平化为1维with tf.name_scope('h_pool2_flat'):h_pool2_flat = tf.reshape(h_pool2,[-1,7*7*64],name='h_pool2_flat')#求第一个全连接的输出with tf.name_scope('h_fc1'):h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat,W_fc1)+ b_fc1)#keep_prob用来表示神经元的输出概率with tf.name_scope('keep_prob'):keep_prob = tf.placeholder(tf.float32,name='keep_prob')with tf.name_scope('h_fc1_drop'):h_fc1_drop = tf.nn.dropout(h_fc1,keep_prob,name='h_fc1_drop1')#初始化第二个全连接的权值
with tf.name_scope('fc2'):with tf.name_scope('W_fc2'):W_fc2 = weight_variable([1024,10])#W_fc2 = weight_variable([1024, 10], name='W_fc2')with tf.name_scope('b_fc2'):# b_fc2 = bias_variable([10],name='b_fc2')  #10代表有10个输出b_fc2 = bias_variable([10])with tf.name_scope('wx_plus_b2'):wx_plus_b2 = tf.matmul(h_fc1_drop,W_fc2)+b_fc2with tf.name_scope('softmax'):#计算输出prediction = tf.nn.softmax(wx_plus_b2)#交差熵代价函数
with tf.name_scope('cross_entropy'):cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=prediction))tf.summary.scalar('cross_entropy',cross_entropy)#使用AdamOptimizer进行优化
with tf.name_scope('train_step'):train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)#求准确率
with tf.name_scope('accuracy'):# 结果存放在一个布尔型列表中with tf.name_scope('correct_prediction'):correct_prediction = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))with tf.name_scope('accuracy'):accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))tf.summary.scalar('accuracy',accuracy)#合并所有的summary
merged = tf.summary.merge_all()with tf.Session() as sess:sess.run(tf.global_variables_initializer())train_writer = tf.summary.FileWriter('logs/train',sess.graph)test_writer = tf.summary.FileWriter('logs/test',sess.graph)for epoch in range(1001):batch_xs,batch_ys = mnist.train.next_batch(batch_size)sess.run(train_step, feed_dict={x:batch_xs,y:batch_ys,keep_prob:1})  #此处的keep_prob并不是越大越好,需要多次训练,每次的值具有随机性#记录训练集计算的参数summary = sess.run(merged, feed_dict={x: batch_xs, y: batch_ys, keep_prob:1.0})train_writer.add_summary(summary, epoch)#记录测试集计算的参数batch_xs,batch_ys=mnist.test.next_batch(batch_size)summary = sess.run(merged, feed_dict={x: batch_xs, y:batch_ys, keep_prob:1.0})test_writer .add_summary(summary, epoch)if epoch % 100 == 0:test_acc = sess.run(accuracy, feed_dict={x: mnist.test.images, y: mnist.test.labels, keep_prob: 1.0})train_acc = sess.run(accuracy, feed_dict={x: mnist.train.images[0:37853], y: mnist.train.labels[:37853],keep_prob: 1.0})**#在保证test的前提下 train 最大值是37853,超过这个会报错**print("epoch " + str(epoch) + " Testing Accuracy," + str(test_acc) + " Training Accuracy," + str(train_acc))

Process finished with exit code 3

#Tensorflow Process finished with exit code 3#相关推荐

  1. TENSORFLOW PROCESS FINISHED WITH EXIT CODE -1073741819 (0XC0000005)

    这次报错与是否gpu没有关系: TENSORFLOW 导入失败:PROCESS FINISHED WITH EXIT CODE -1073741819 (0XC0000005) 测试脚本: impor ...

  2. tensorflow Process finished with exit code -1073740791 (0xC0000409)

    记录一下,链接为解决方案.感谢这位大佬 https://blog.csdn.net/jyfhaoshuai/article/details/124745161

  3. TensorFlow example示例 Process finished with exit code -1073741819 (0xC0000005)

    在做MNIST示例学习的时候,运行后一直出现Process finished with exit code -1073741819 (0xC0000005)的问题,起初以为是数据集下载的问题,所以在官 ...

  4. TensorFlow 2+PyCharm显示“Process finished with exit code -1073740791 (0xC0000409)”

    目录 大致现象 第一个坑:PyCharm不显示报错信息 第二个坑:解决"Could not locate zlibwapi.dll" 大致现象 TensorFlow.Keras中的 ...

  5. Windows fatal exception: access violation / Process finished with exit code -1073741819 (0xC0000005)

    解决Pycharm报错 Windows fatal exception: access violation 以及Process finished with exit code -1073741819 ...

  6. pycharm报错:Process finished with exit code -1073741819 (0xC0000005)

    问题描述: 在配置tensorflow环境时,发现在Pycharm中运行相关代码时,会出现运行结束,报错如下 Process finished with exit code -1073741819 ( ...

  7. python Process finished with exit code -1073741819 (0xC0000005) 解决

    运行程序时,Process finished with exit code -1073741819 (0xC0000005) 报错 原因:没有 python33.dll 在 c:\WINDOWS\sy ...

  8. Process finished with exit code -1073741819 (0xC0000005)

    Process finished with exit code -1073741819 (0xC0000005) pycharm报错:Process finished with exit code - ...

  9. Pycharm debug出现Qt 错误 Process finished with exit code -1073741819 (0xC0000005)

    使用pycharm debug的时候出现 This application failed to start because it could not find or load the Qt platf ...

最新文章

  1. 牛客网在线编程----算法入门篇
  2. LSI SAS 3108 配置操作
  3. Linux文件服务器实战(系统用户)
  4. 【CTR模型】TensorFlow2.0 的 xDeepFM 实现与实战(附代码+数据)
  5. .NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 )...
  6. LeetCode题库整理【Java】—— 2 两数相加
  7. 使用navicat for mysql 创建外键foreign keys时,总会自动创建索引indexs
  8. 深入理解并行编程pdf
  9. java利用xml生成excel_代码快速 实现xml 转换为 Excel(xml转excel通用类-java-完成代码可作工具使用).doc...
  10. 【渝粤题库】陕西师范大学209004道德教育案例研究 作业 (高起专)
  11. 移动MM要走进大学!
  12. 事件委托(代理)的理解
  13. 塑造棋牌游戏文化内涵
  14. php钓鱼怎么使用方法,盘钩使用方法
  15. 2021-05-11 MongoDB面试题 MySQL与MongoDB之间最基本的差别是什么
  16. 跳动爱心代码-李峋爱心代码(手把手教学)
  17. 微信小程序通过服务号推送模板消息
  18. 集成讯飞离线语音合成SDK报:“ 未经授权的语音应用.(错误码:11210)“ 问题解决
  19. 02-windows调试工具(DebugDiag使用)
  20. netbean 偶尔无法设置断点问题

热门文章

  1. 业界大佬揭秘美颜技术的算法原理
  2. 【CSS基础】文字垂直居中
  3. 蓝牙耳机选什么好?5款主打高性价比的蓝牙耳机推荐
  4. 北理工嵩天Python学习笔记
  5. 蛙蛙推荐:蛙蛙教你文本聚类
  6. 文华学院计算机专业师资,华中科技大学文华学院“最受欢迎教师”名单
  7. 园区网络三层架构实验
  8. 吴松计算机学院,IT|“创青春”创业大赛计算机学院选拔赛成功举行!
  9. 程序员为什么不会修电脑
  10. 三菱je-a系列伺服支持modbusrtu 协议吗_你了解吗?全新正品英飞凌模块全新现货...