conv1 = tf.nn.relu(tf.nn.conv2d(images, weights['w1'], strides=[1,1,1,1], padding=padding) + biases['b1'])
conv2 = tf.nn.relu(tf.nn.conv2d(conv1, weights['w2'], strides=[1,1,1,1], padding=padding) + biases['b2'])
conv3 = tf.nn.conv2d(conv2, weights['w3'], strides=[1,1,1,1], padding=padding) + biases['b3']
saver=tf.train.Saver()
pred1=conv1
pred=conv3
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state("checkpoint")
if ckpt and ckpt.model_checkpoint_path: # 加載保存的模型
saver.restore(sess, ckpt.model_checkpoint_path)
#img1 = (weights['w1'].eval()) #查看卷積核是否在變化
pred2 = pred1.eval({images: train_data, labels: train_label})
split = tf.split(pred2, pred2.shape[-1], axis=3)
print(len(split))
for i in range(64):
img1=split[i]
io.imsave(r'./data/{}.png',format(i),img1)
result = pred.eval({images: train_data, labels: train_label}) #得到訓練后的結果
以上是部分代碼
其中想把第一層輸出的64個影像保存到指定檔案夾中,想請教一下各位大佬要如何改下面的代碼:
for i in range(64):
img1=split[i]
io.imsave(r'./data/{}.png',format(i),img1)
報錯:Traceback (most recent call last):
File "step3-test.py", line 86, in <module>
io.imsave(r'./data/{}.png',format(i),img1)
File "python3.7/site-packages/skimage/io/_io.py", line 129, in imsave
if arr.dtype == bool:
AttributeError: 'str' object has no attribute 'dtype'
謝謝各位大佬!
uj5u.com熱心網友回復:
其中split輸出是這樣的 想把它轉換為影像保存[<tf.Tensor 'split:0' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:1' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:2' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:3' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:4' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:5' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:6' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:7' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:8' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:9' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:10' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:11' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:12' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:13' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:14' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:15' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:16' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:17' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:18' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:19' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:20' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:21' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:22' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:23' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:24' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:25' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:26' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:27' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:28' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:29' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:30' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:31' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:32' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:33' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:34' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:35' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:36' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:37' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:38' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:39' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:40' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:41' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:42' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:43' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:44' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:45' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:46' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:47' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:48' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:49' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:50' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:51' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:52' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:53' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:54' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:55' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:56' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:57' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:58' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:59' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:60' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:61' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:62' shape=(1, 342, 228, 1) dtype=float32>, <tf.Tensor 'split:63' shape=(1, 342, 228, 1) dtype=float32>]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/194559.html
上一篇:python題目
下一篇:移動公網5G配置(二)
