哎呀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 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统