tensorflow运行时错误:服务似乎挂掉了,但是会立刻重启的.
以前在POD里跑起来,没问题的示例代码。
移到jupyter中,多给两个GPU,有时运行就会爆出这个错误:
于是,按网上的意见,暂时加了个使用GPU的指定,
暂时搞定。
如下红色部分。
import timeit
import os
import tensorflow as tf
import numpy as np
from tensorflow.keras.datasets.cifar10 import load_data
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1'
def model():
x = tf.placeholder(tf.float32, shape=[None, 32, 32, 3])
y = tf.placeholder(tf.float32, shape=[None, 10])
rate = tf.placeholder(tf.float32)
# convolutional layer 1
conv_1 = tf.layers.conv2d(x, 32, [3, 3], padding='SAME', activation=tf.nn.relu)
max_pool_1 = tf.layers.max_pooling2d(conv_1, [2, 2], strides=2, padding='SAME')
drop_1 = tf.layers.dropout(max_pool_1, rate=rate)
# convolutional layer 2
conv_2 = tf.layers.conv2d(drop_1, 64, [3, 3], padding="SAME", activation=tf.nn.relu)
max_pool_2 = tf.layers.max_pooling2d(conv_2, [2, 2], strides=2, padding="SAME")
drop_2 = tf.layers.dropout(max_pool_2, rate=rate)
# convolutional layers 3
conv_3 = tf.layers.conv2d(drop_2, 128, [3, 3], padding="SAME", activation=tf.nn.relu)
max_pool_3 = tf.layers.max_pooling2d(conv_3, [2, 2], strides=2, padding="SAME")
drop_3 = tf.layers.dropout(max_pool_3, rate=rate)
# fully connected layer 1
flat = tf.reshape(drop_3, shape=[-1, 4 * 4 * 128])
fc_1 = tf.layers.dense(flat, 80, activation=tf.nn.relu)
drop_4 = tf.layers.dropout(fc_1 , rate=rate)
# fully connected layer 2 or the output layers
fc_2 = tf.layers.dense(drop_4, 10)
output = tf.nn.relu(fc_2)
# accuracy
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(output, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
# loss
loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=output, labels=y))
# optimizer
optimizer = tf.train.AdamOptimizer(1e-4, beta1=0.9, beta2=0.999, epsilon=1e-8).minimize(loss)
return x, y, rate, accuracy, loss, optimizer
def one_hot_encoder(y):
ret = np.zeros(len(y) * 10)
ret = ret.reshape([-1, 10])
for i in range(len(y)):
ret[i][y[i]] = 1
return (ret)
def train(x_train, y_train, sess, x, y, rate, optimizer, accuracy, loss):
batch_size = 128
y_train_cls = one_hot_encoder(y_train)
start = end = 0
for i in range(int(len(x_train) / batch_size)):
if (i + 1) % 100 == 1:
start = timeit.default_timer()
batch_x = x_train[i * batch_size:(i + 1) * batch_size]
batch_y = y_train_cls[i * batch_size:(i + 1) * batch_size]
_, batch_loss, batch_accuracy = sess.run([optimizer, loss, accuracy], feed_dict={x:batch_x, y:batch_y, rate:0.4})
if (i + 1) % 100 == 0:
end = timeit.default_timer()
print("Time:", end-start, "s the loss is ", batch_loss, " and the accuracy is ", batch_accuracy * 100, "%")
def test(x_test, y_test, sess, x, y, rate, accuracy, loss):
batch_size = 64
y_test_cls = one_hot_encoder(y_test)
global_loss = 0
global_accuracy = 0
for t in range(int(len(x_test) / batch_size)):
batch_x = x_test[t * batch_size : (t + 1) * batch_size]
batch_y = y_test_cls[t * batch_size : (t + 1) * batch_size]
batch_loss, batch_accuracy = sess.run([loss, accuracy], feed_dict={x:batch_x, y:batch_y, rate:1})
global_loss += batch_loss
global_accuracy += batch_accuracy
global_loss = global_loss / (len(x_test) / batch_size)
global_accuracy = global_accuracy / (len(x_test) / batch_size)
print("In Test Time, loss is ", global_loss, ' and the accuracy is ', global_accuracy)
EPOCH = 100
(x_train, y_train), (x_test, y_test) = load_data()
print("There is ", len(x_train), " training images and ", len(x_test), " images")
x, y, rate, accuracy, loss, optimizer = model()
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for i in range(EPOCH):
print("Train on epoch ", i ," start")
train(x_train, y_train, sess, x, y, rate, optimizer, accuracy, loss)
test(x_train, y_train, sess, x, y, rate, accuracy, loss)
tensorflow运行时错误:服务似乎挂掉了,但是会立刻重启的.的更多相关文章
- TensorFlow Serving-TensorFlow 服务
TensorFlow服务是一个用于服务机器学习模型的开源软件库.它处理机器学习的推断方面,在培训和管理他们的生命周期后采取模型,通过高性能,引用计数的查找表为客户端提供版本化访问. 可以同时提供多个模 ...
- linux 编写定时任务,查询服务是否挂掉
shell 脚本 #!/bin/bash a=`netstat -unltp|grep fdfs|wc -l` echo "$a" if [ "$a" -ne ...
- 平时服务正常,突然挂了,怎么重启都起不来,查看日志Insufficient space for shared memory file 内存文件空间不足
Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: /tmp/hsperfd ...
- nodejs-Cluster模块
JavaScript 标准参考教程(alpha) 草稿二:Node.js Cluster模块 GitHub TOP Cluster模块 来自<JavaScript 标准参考教程(alpha)&g ...
- 踩坑踩坑之Flask+ uWSGI + Tensorflow的Web服务部署
一.简介 作为算法开发人员,在算法模块完成后,拟部署Web服务以对外提供服务,从而将算法模型落地应用.本文针对首次基于Flask + uWSGI + Tensorflow + Nginx部署Web服务 ...
- Dubbo框架中的应用(两)--服务治理
Dubbo服务治理了看法 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlzaGVoZQ==/font/5a6L5L2T/fontsize/400/fi ...
- 【深度解析】Google第二代深度学习引擎TensorFlow开源
作者:王嘉俊 王婉婷 TensorFlow 是 Google 第二代深度学习系统,今天宣布完全开源.TensorFlow 是一种编写机器学习算法的界面,也可以编译执行机器学习算法的代码.使用 Tens ...
- linux下监视进程 崩溃挂掉后自动重启的shell脚本
如何保证服务一直运行?如何保证即使服务挂掉了也能自动重启?在写服务程序时经常会碰到这样的问题.在Linux系统中,强大的shell就可以很灵活的处理这样的事务. 下面的shell通过一个while-d ...
- java 服务治理办法
在大规模服务化之前.应用可能仅仅是通过RMI或Hessian等工具.简单的暴露和引用远程服务,通过配置服务的URL地址进行调用.通过F5等硬件进行负载均衡. (1) 当服务越来越多时.服务URL配置管 ...
随机推荐
- Tomcat服务部署与Nginx负载均衡配置
一.中间键产品介绍 目前来说IBM的WebSphere,Oracle的Weblogic占据了市场上java语言Web站点的部分份额,该两种软件都是商业化的软件,由于性能优越,可靠性高等优点应用于大型互 ...
- 第02组 Beta冲刺(4/4)
队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:了解整个游戏的流程 GitHub签入记录 接下来的计划:继续完成游戏 还剩下哪些任务:完成游戏 燃尽图 遇到的困难:没有美术比较好的 ...
- Linux性能优化实战学习笔记:第十三讲
问题1:性能工具版本太低,导致指标不全 解决方案1: 这是使用 CentOS 的同学普遍碰到的问题.在文章中,我的pidstat 输出里有一个 %wait 指标,代表进程等待 CPU 的时间百分比, ...
- [LeetCode] 46. Permutations 全排列
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
- 微信小程序之页面打开数量限制
无论是在小程序还是APP中,打开一个页面其实就是创建了一个新的View对象,一层层叠加的.当点击页面的回退按钮就是把当前页面关闭. 这个过程中会涉及到一个问题,就是打开页面的数量.在某些设计下,比如一 ...
- 姿态角(RPY)的优化目标函数
在Pose-Graph的过程中,如果使用G2O优化函数库,那么似乎是不用自己编写代价函数(也就是优化目标函数)的,因为G2O有封装好的SE3等格式,使得Pose-Graph的过程变得简单了,即只需要设 ...
- c# linq分组 lambda分组
var groupResults = from gr in models && gr.Temperature != && gr.Humidity != &&am ...
- 批量插入sql技巧
方式一: ); ); 方式二: ), (); 第二种比较好.第二种的SQL执行效率高的主要原因是合并后日志量(MySQL的binlog和innodb的事务让日志)减少了,降低日志刷盘的数据量和频率,从 ...
- 使用windows 上的远程连接来远程Linux Ubuntu系统的设置
实验环境: Windows 10 , VMware Workstation ,Ubuntu16.04 1.root登录ubuntu,然后执行下面的命令 # root账户登录ubuntu ,执行下面的命 ...
- ng 使用阿里巴巴矢量图
1.进入阿里巴巴矢量图标库中,选择需要下载的图标,添加进项目中 2.进去项目选择Font class 模式,然后下载到本地 3.解压下载的压缩包,把.css/.svg/.ttf/.woff/.woff ...