error in data shape with conv2D layer keras
i am a biginner in neural networks,
i get the following error when running fit,
ValueError: Error when checking target: expected conv2d_1 to have shape (64, 222, 222) but got array with shape (1, 224, 224)
i use grayscale images, as far as i know i think i'm shaping the input correctly.
i cant get what i'm doing wrong.
here is a snippet of the network
network model:
def convLayer(channels):
return
Conv2D(channels,kernel_size=3,activation='relu',
kernel_initializer=initializers.random_normal(mean=0.0, stddev=0.01),
data_format='channels_first')
class est_net():
def __init__(self, input=None):
if input is None:
input=Input(shape=(1,224,224))
self.input=input
conv1_1 = convLayer(64)(self.input)
self.output = conv1_1
self.CDECNN = Model(inputs=self.input, outputs=self.output)
print(self.CDECNN.summary())
reading data:
def __iter__(self):
files=self.img_files
for f in files:
if f==".DS_Store":
continue
img=cv2.imread(os.path.join(self.img_path,f),cv2.COLOR_BGR2GRAY)
img=img.reshape(1, img.shape[0], img.shape[1])
if img is None:
print("unable to read image %s." % f)
exit(0)
gt_file='GT_'+f.split('.')[0]+'.mat'
gt=sio.loadmat(os.path.join(self.gt_path,gt_file))['d_map']
gt=gt.reshape(1, gt.shape[0], gt.shape[1])
yield(img,gt)
training:
input_img= #representing input segment images to be fed to the network
actual_dgt= #representing the actual dot-map ground-truth
for i, (img, dgt) in enumerate(training_DS):
input_img.append(img)
actual_dgt.append(dgt)
#initializing training parameters
sgd=optimizers.SGD(lr=0.01, decay=0.0005, momentum=0.9)
#compiling the network and defining the loss method
net.CDECNN.compile(optimizer=sgd, loss='mean_squared_error')
#training CDECNN network on training data
training_log=net.CDECNN.fit(np.array(input_img), np.array(actual_dgt), batch_size=1, epochs=5)
python keras conv-neural-network reshape shapes
add a comment |
i am a biginner in neural networks,
i get the following error when running fit,
ValueError: Error when checking target: expected conv2d_1 to have shape (64, 222, 222) but got array with shape (1, 224, 224)
i use grayscale images, as far as i know i think i'm shaping the input correctly.
i cant get what i'm doing wrong.
here is a snippet of the network
network model:
def convLayer(channels):
return
Conv2D(channels,kernel_size=3,activation='relu',
kernel_initializer=initializers.random_normal(mean=0.0, stddev=0.01),
data_format='channels_first')
class est_net():
def __init__(self, input=None):
if input is None:
input=Input(shape=(1,224,224))
self.input=input
conv1_1 = convLayer(64)(self.input)
self.output = conv1_1
self.CDECNN = Model(inputs=self.input, outputs=self.output)
print(self.CDECNN.summary())
reading data:
def __iter__(self):
files=self.img_files
for f in files:
if f==".DS_Store":
continue
img=cv2.imread(os.path.join(self.img_path,f),cv2.COLOR_BGR2GRAY)
img=img.reshape(1, img.shape[0], img.shape[1])
if img is None:
print("unable to read image %s." % f)
exit(0)
gt_file='GT_'+f.split('.')[0]+'.mat'
gt=sio.loadmat(os.path.join(self.gt_path,gt_file))['d_map']
gt=gt.reshape(1, gt.shape[0], gt.shape[1])
yield(img,gt)
training:
input_img= #representing input segment images to be fed to the network
actual_dgt= #representing the actual dot-map ground-truth
for i, (img, dgt) in enumerate(training_DS):
input_img.append(img)
actual_dgt.append(dgt)
#initializing training parameters
sgd=optimizers.SGD(lr=0.01, decay=0.0005, momentum=0.9)
#compiling the network and defining the loss method
net.CDECNN.compile(optimizer=sgd, loss='mean_squared_error')
#training CDECNN network on training data
training_log=net.CDECNN.fit(np.array(input_img), np.array(actual_dgt), batch_size=1, epochs=5)
python keras conv-neural-network reshape shapes
add a comment |
i am a biginner in neural networks,
i get the following error when running fit,
ValueError: Error when checking target: expected conv2d_1 to have shape (64, 222, 222) but got array with shape (1, 224, 224)
i use grayscale images, as far as i know i think i'm shaping the input correctly.
i cant get what i'm doing wrong.
here is a snippet of the network
network model:
def convLayer(channels):
return
Conv2D(channels,kernel_size=3,activation='relu',
kernel_initializer=initializers.random_normal(mean=0.0, stddev=0.01),
data_format='channels_first')
class est_net():
def __init__(self, input=None):
if input is None:
input=Input(shape=(1,224,224))
self.input=input
conv1_1 = convLayer(64)(self.input)
self.output = conv1_1
self.CDECNN = Model(inputs=self.input, outputs=self.output)
print(self.CDECNN.summary())
reading data:
def __iter__(self):
files=self.img_files
for f in files:
if f==".DS_Store":
continue
img=cv2.imread(os.path.join(self.img_path,f),cv2.COLOR_BGR2GRAY)
img=img.reshape(1, img.shape[0], img.shape[1])
if img is None:
print("unable to read image %s." % f)
exit(0)
gt_file='GT_'+f.split('.')[0]+'.mat'
gt=sio.loadmat(os.path.join(self.gt_path,gt_file))['d_map']
gt=gt.reshape(1, gt.shape[0], gt.shape[1])
yield(img,gt)
training:
input_img= #representing input segment images to be fed to the network
actual_dgt= #representing the actual dot-map ground-truth
for i, (img, dgt) in enumerate(training_DS):
input_img.append(img)
actual_dgt.append(dgt)
#initializing training parameters
sgd=optimizers.SGD(lr=0.01, decay=0.0005, momentum=0.9)
#compiling the network and defining the loss method
net.CDECNN.compile(optimizer=sgd, loss='mean_squared_error')
#training CDECNN network on training data
training_log=net.CDECNN.fit(np.array(input_img), np.array(actual_dgt), batch_size=1, epochs=5)
python keras conv-neural-network reshape shapes
i am a biginner in neural networks,
i get the following error when running fit,
ValueError: Error when checking target: expected conv2d_1 to have shape (64, 222, 222) but got array with shape (1, 224, 224)
i use grayscale images, as far as i know i think i'm shaping the input correctly.
i cant get what i'm doing wrong.
here is a snippet of the network
network model:
def convLayer(channels):
return
Conv2D(channels,kernel_size=3,activation='relu',
kernel_initializer=initializers.random_normal(mean=0.0, stddev=0.01),
data_format='channels_first')
class est_net():
def __init__(self, input=None):
if input is None:
input=Input(shape=(1,224,224))
self.input=input
conv1_1 = convLayer(64)(self.input)
self.output = conv1_1
self.CDECNN = Model(inputs=self.input, outputs=self.output)
print(self.CDECNN.summary())
reading data:
def __iter__(self):
files=self.img_files
for f in files:
if f==".DS_Store":
continue
img=cv2.imread(os.path.join(self.img_path,f),cv2.COLOR_BGR2GRAY)
img=img.reshape(1, img.shape[0], img.shape[1])
if img is None:
print("unable to read image %s." % f)
exit(0)
gt_file='GT_'+f.split('.')[0]+'.mat'
gt=sio.loadmat(os.path.join(self.gt_path,gt_file))['d_map']
gt=gt.reshape(1, gt.shape[0], gt.shape[1])
yield(img,gt)
training:
input_img= #representing input segment images to be fed to the network
actual_dgt= #representing the actual dot-map ground-truth
for i, (img, dgt) in enumerate(training_DS):
input_img.append(img)
actual_dgt.append(dgt)
#initializing training parameters
sgd=optimizers.SGD(lr=0.01, decay=0.0005, momentum=0.9)
#compiling the network and defining the loss method
net.CDECNN.compile(optimizer=sgd, loss='mean_squared_error')
#training CDECNN network on training data
training_log=net.CDECNN.fit(np.array(input_img), np.array(actual_dgt), batch_size=1, epochs=5)
python keras conv-neural-network reshape shapes
python keras conv-neural-network reshape shapes
edited Nov 20 '18 at 15:30
norahik
asked Nov 20 '18 at 11:01
norahiknorahik
13
13
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391556%2ferror-in-data-shape-with-conv2d-layer-keras%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391556%2ferror-in-data-shape-with-conv2d-layer-keras%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown