0
크기 [256 256 3]의 이미지를 입력으로 제공하고 같은 크기의 출력을 원하지만 아래에 언급 된 오류가 표시됩니다. 나는 셰이프, 필터, 스트라이드를 변경하려고 시도했지만 아무것도 작동하지 않습니다. 동일한 것을 성취하는 다른 방법은 상기와 동일하게 인식되거나 링크 될 것이며, 입력과 출력은 모두 이미지입니다.tflearn conv2d_transpose 모양이 호환되지 않음
enter code here
import tensorflow as tf
import tflearn
import os
import numpy as np
from tflearn.layers.conv import conv_2d, max_pool_2d,conv_2d_transpose
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
import loaddata
LR = 1e-3
MODEL_NAME = 'deblurr-{}-{}.model'.format(LR, '2conv-basic')
IMG_SIZE = 256
strides = [1,2,2,1]
convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 3],dtype=tf.float32,
name='input')
print ("convnet :" , convnet.shape)
convnet = conv_2d(convnet, 6, 5,strides=strides, activation='LeakyReLU')
print ("convnet :" , convnet.shape)
convnet = conv_2d(convnet,12, 5,strides=strides, activation='LeakyReLU')
print ("convnet :" , convnet.shape)
convnet = conv_2d(convnet, 24, 5,strides=strides, activation='LeakyReLU')
print ("convnet :" , convnet.shape)
convnet = conv_2d(convnet, 48, 5,strides=strides, activation='LeakyReLU')
print ("convnet :" , convnet.shape)
convnet = conv_2d(convnet, 24, 5,strides=strides, activation='LeakyReLU')
print ("convnet :" , convnet.shape)
convnet = conv_2d_transpose(convnet, 12, 5,output_shape=
[64,64,12],strides=strides, activation='tanh')
print ("convnet :" , convnet.shape)
convnet = dropout(convnet, 0.8)
print ("convnet :" , convnet.shape)
convnet = conv_2d_transpose(convnet, 6, 5,output_shape=
[128,128,6],strides=strides, activation='tanh')
print ("convnet :" , convnet.shape)
convnet = dropout(convnet, 0.8)
print ("convnet :" , convnet.shape)
convnet = conv_2d_transpose(convnet, 3, 5,output_shape=
[256,256,3],strides=strides, activation='tanh')
print ("convnet :" , convnet.shape)
convnet = dropout(convnet, 0.8)
print ("convnet :" , convnet.shape)
convnet = regression(convnet, optimizer='adam', learning_rate=LR,
loss='categorical_crossentropy', name='targets')
print ("convnet :" , convnet.shape)
model = tflearn.models.dnn.DNN(convnet)
if os.path.exists('{}.meta'.format(MODEL_NAME)):
model.load(MODEL_NAME)
print('model loaded!')
y_train, x_train = loaddata.load_data(data_type='train')
X = x_train
Y = y_train
y_test, x_test = loaddata.load_data(data_type='test')
test_x = y_test
test_y = x_test
model.fit({'input': X}, {'targets': Y}, n_epoch=10, validation_set=({'input':
test_x}, {'targets': test_y}), batch_size=2,
snapshot_step=500, show_metric=True, run_id=MODEL_NAME)
이로 나오는 오류 : 당신이 당신의 전환 레이어에서 모양 출력을 보면
ValueError Traceback (most recent call last)
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py in merge_with(self, other)
562 for i, dim in enumerate(self._dims):
--> 563 new_dims.append(dim.merge_with(other[i]))
564 return TensorShape(new_dims)
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py in merge_with(self, other)
137 other = as_dimension(other)
--> 138 self.assert_is_compatible_with(other)
139 if self._value is None:
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py in assert_is_compatible_with(self, other)
110 raise ValueError("Dimensions %s and %s are not compatible" % (self,
--> 111 other))
112
ValueError: Dimensions 32 and 8 are not compatible
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
E:\extra\notes\New folder\source\models.py in <module>()
53 print ("convnet :" , convnet.shape)
54
---> 55 model = tflearn.models.dnn.DNN(convnet)
56
57 if os.path.exists('{}.meta'.format(MODEL_NAME)):
C:\Users\USER\Anaconda3\lib\site-packages\tflearn\models\dnn.py in __init__(self, network, clip_gradients, tensorboard_verbose, tensorboard_dir, checkpoint_path, best_checkpoint_path, max_checkpoints, session, best_val_accuracy)
63 max_checkpoints=max_checkpoints,
64 session=session,
---> 65 best_val_accuracy=best_val_accuracy)
66 self.session = self.trainer.session
67
C:\Users\USER\Anaconda3\lib\site-packages\tflearn\helpers\trainer.py in __init__(self, train_ops, graph, clip_gradients, tensorboard_dir, tensorboard_verbose, checkpoint_path, best_checkpoint_path, max_checkpoints, keep_checkpoint_every_n_hours, random_seed, session, best_val_accuracy)
129 train_op.initialize_training_ops(i, self.session,
130 tensorboard_verbose,
--> 131 clip_gradients)
132
133 # Saver for saving a model
C:\Users\USER\Anaconda3\lib\site-packages\tflearn\helpers\trainer.py in initialize_training_ops(self, i, session, tensorboard_verbose, clip_gradients)
695 # Compute gradients operations
696 with tf.control_dependencies([loss_avg_op, acc_avg_op]):
--> 697 self.grad = tf.gradients(total_loss, self.train_vars)
698 if clip_gradients > 0.0:
699 self.grad, self.grad_norm = \
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\ops\gradients_impl.py in gradients(ys, xs, grad_ys, name, colocate_gradients_with_ops, gate_gradients, aggregation_method)
560 if (isinstance(in_grad, ops.Tensor) and
561 t_in.dtype != dtypes.resource):
--> 562 in_grad.set_shape(t_in.get_shape())
563 _SetGrad(grads, t_in, in_grad)
564 if loop_state:
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in set_shape(self, shape)
376 this tensor.
377 """
--> 378 self._shape = self._shape.merge_with(shape)
379
380 @property
C:\Users\USER\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py in merge_with(self, other)
564 return TensorShape(new_dims)
565 except ValueError:
--> 566 raise ValueError("Shapes %s and %s are not compatible" % (self, other))
567
568 def concatenate(self, other):
ValueError: Shapes (?, 32, 32, 24) and (?, 8, 8, 24) are not compatible
주어진 두 개의 레이어와 그 반대로 스케일을 계산하는 방법은 무엇입니까? –
입력 모양이 [?, H1, W1 ,?]이고 출력 모양이 [?, H2, W2 ,?] 인 경우 스트라이드는 [1, H2/H1, W2/W1,1]이어야합니다. –