我是深度学习的新手,我有一个问题,我无法弄清楚5天。所以我非常失望。我需要一些帮助,指点等等。
我正在尝试创建一个图像分类模型,该模型看起来是2个图像并决定一个热的9长度数组。像:
[0,1,0,0,0,0,0,0,0]
并且两张图片的尺寸为480x720像素。
我确实尝试了几件事,但编译器总是说我
ValueError:使用序列设置数组元素。
创建培训数据时,
training_data = []
...
while(loop):
...
training_data.append([image1,image2, output])
...
if(...):
np.save('train_data.npy', training_data)
当我读数据时,
train = np.load('train_data.npy')
X=train[:,:2]
Y=train[:,2]
for i in range(0,len(X)):
X[i][0] = X[i][0].reshape(-1,480,720,1)
X[i][1] = X[i][0].reshape(-1,480,720,1)
WIDTH = 480
HEIGHT = 720
LR = 1e-3
EPOCHS = 10
OUTPUT_SHAPE= 9
model = alexnetf(WIDTH, HEIGHT,LR,OUTPUT_SHAPE)
model.fit(X, Y, n_epoch=EPOCHS, validation_split=0.1, snapshot_step=500, show_metric=True, run_id=MODEL_NAME)
我在5天内看不出任何错误,但它无法正常工作。我真的需要任何打击,想法等......
用于创建列车数据
print(type(image1)) #->(gives as output) <class 'numpy.ndarray'>
print(image1.shape) #-> (480, 720)
print(type(image2)) #-> <class 'numpy.ndarray'>
print(image2.shape) #-> (480, 720)
print(type(output)) #-> <class 'list'>
print(len(output)) #-> 9
用于创建模型
print(X.shape) #->(gives as output) (1200, 2)
print(X[0].shape) #-> (2,)
print(X[0,0].shape) #-> (1, 480, 720, 1)
print(Y.shape) #-> (1200,)
alexnet:
import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
from tflearn.layers.normalization import local_response_normalization
def alexnet(width, height, lr, output):
network = input_data(shape=[None, width, height, 1], name='input')
network = conv_2d(network, 96, 11, strides=4, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 256, 5, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 256, 3, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, output, activation='softmax')
network = regression(network, optimizer='momentum',
loss='categorical_crossentropy',
learning_rate=lr, name='targets')
model = tflearn.DNN(network, checkpoint_path='model_alexnet',
max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='log')
return model
完全错误消息:
Traceback (most recent call last):
File "C:/Users/Joo/PycharmProjects/cv2/create_model.py", line 93, in <module>
model.fit(X, Y, n_epoch=EPOCHS, validation_split=0.1, snapshot_step=500, show_metric=True, run_id=MODEL_NAME)
File "D:\Program files\Anaconda3\lib\site-packages\tflearn\models\dnn.py", line 216, in fit
callbacks=callbacks)
File "D:\Program files\Anaconda3\lib\site-packages\tflearn\helpers\trainer.py", line 339, in fit
show_metric)
File "D:\Program files\Anaconda3\lib\site-packages\tflearn\helpers\trainer.py", line 818, in _train
feed_batch)
File "D:\Program files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 889, in run
run_metadata_ptr)
File "D:\Program files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1089, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "D:\Program files\Anaconda3\lib\site-packages\numpy\core\numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.