哎呀100 2018-11-01 09:57 采纳率: 0%
浏览 773
已采纳

求各位大神看一下哪里错了,怎么改。

错误:
ValueError: setting an array element with a sequence.

import tensorflow as tf
import scipy.io as sio
import numpy as np
import matplotlib.image as mpimg
import pickle as cp
import matplotlib.pyplot as plt
def get_batch(image, label, batch_size, now_batch, total_batch):
if now_batch < total_batch-1:
image_batch = image[now_batch*batch_size:(now_batch+1)*batch_size]
label_batch = label[now_batch*batch_size:(now_batch+1)*batch_size]
else:
image_batch = image[now_batch*batch_size:]
label_batch = label[now_batch*batch_size:]
return image_batch,label_batch

label_tain = list(sio.loadmat('dataset/corel5k_train_annot.mat')['annot1']) #加载文件

label_test = list(sio.loadmat('dataset/corel5k_test_annot.mat')['annot2'])

test_img = []
with open('dataset/corel5k_test_list.txt') as f:
for i in f.readlines():
test_img += [mpimg.imread('dataset/%s.jpeg'%i.strip())]
cp.dump(test_img,open("test.pkl","wb"))#一种保存列表的方式

train_img = []
with open('dataset/corel5k_train_list.txt') as f:
for i in f.readlines():
train_img += [mpimg.imread('dataset/%s.jpeg'%i.strip())]
cp.dump(train_img,open("train.pkl","wb"))

length=len(train_img)
for e in range(1,length+1):
train_img[e-1] = tf.image.resize_images(train_img[e-1], [128,192], method=0)
train_img[e-1] = tf.image.per_image_standardization(train_img[e-1])

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)

########卷积层、池化层接下来重复使用的,分别定义创建函数########

tf.nn.conv2d是TensorFlow中的2维卷积函数

def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')

使用2*2的最大池化

def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],strides=[1, 2, 2, 1], padding='SAME')
x = tf.placeholder(tf.float32,[None,128,192,3])
y_ = tf.placeholder(tf.float32,[None,260])

W_conv1 = weight_variable([3, 3, 3, 32])

用conv2d函数进行卷积操作,加上偏置

b_conv1 = bias_variable([32])

把x_image和权值向量进行卷积,加上偏置项,然后应用ReLU激活函数,

h_conv1 = tf.nn.relu(conv2d(x, W_conv1) + b_conv1)
#tf.global_variables_initializer().run()

对卷积的输出结果进行池化操作

h_pool1 = max_pool_2x2(h_conv1)
image_batch,label_batch = get_batch(train_img, label_train,5,0,9)

with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(h_pool1,feed_dict={x:image_batch,y_:label_batch})

  • 写回答

1条回答 默认 最新

  • devmiao 2018-11-04 15:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料