Tensor input in keras model is array of tensors but won't agree to dimensionsTensorFlow and Categorical variablesHow do i pass data into keras?Keras LSTM: use weights from Keras model to replicate predictions using numpyKeras CNN image input and outputWhat does SpatialDropout1D() do to output of Embedding() in Keras?Why does my Keras model learn to recognize the background?Value error in Merging two different models in kerasmodel.predict in Keras, Python errorImport the same interval of previous week into the deep modelKeras input shape returning an error

Turning a hard to access nut?

Reasons for having MCU pin-states default to pull-up/down out of reset

Why are there no stars visible in cislunar space?

Why doesn't the fusion process of the sun speed up?

Are stably rational surfaces all rational?

Why is participating in the European Parliamentary elections used as a threat?

How to balance a monster modification (zombie)?

Single word to change groups

How can an organ that provides biological immortality be unable to regenerate?

Error in master's thesis, I do not know what to do

The multiplication of list of matrices

Why is indicated airspeed rather than ground speed used during the takeoff roll?

categorizing a variable turns it from insignificant to significant

1 John in Luther’s Bibel

How do you justify more code being written by following clean code practices?

Do people actually use the word "kaputt" in conversation?

How do researchers send unsolicited emails asking for feedback on their works?

The English Debate

Print last inputted byte

Does fire aspect on a sword destroy mob drops?

Determine voltage drop over 10G resistors with cheap multimeter

What is it called when someone votes for an option that's not their first choice?

What do the positive and negative (+/-) transmit and receive pins mean on Ethernet cables?

Adding axes to figures



Tensor input in keras model is array of tensors but won't agree to dimensions


TensorFlow and Categorical variablesHow do i pass data into keras?Keras LSTM: use weights from Keras model to replicate predictions using numpyKeras CNN image input and outputWhat does SpatialDropout1D() do to output of Embedding() in Keras?Why does my Keras model learn to recognize the background?Value error in Merging two different models in kerasmodel.predict in Keras, Python errorImport the same interval of previous week into the deep modelKeras input shape returning an error













0












$begingroup$


This is probably a very stupid question but the regular confusion of arrays and tensors in speech makes me unable to find any answer on the net.



If have a samples long array of "tensorflow.python.framework.ops.Tensor" which are indeed correct numpy arrays of size (299,299,3) once evaluated. My model (inceptionv3) accepts default input of size (299,299,3). Why does it only recognize my input as a (samples, 1) array ? Do I really need to evaluate each tensor ? As evaluating one takes like 5s ...



How can I change the input of the model to get the model working ?
Or how can I change my tensors in a reasonable time to the right format?



I have :



train_images.shape Out[170]: (24,)


Precisely:



train_images
Out[167]:
[<tf.Tensor 'Squeeze_3:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_4:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_5:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_6:0' shape=(299, 299, 3) dtype=float32>,



And:



type(train_images[1]) Out[168]: tensorflow.python.framework.ops.Tensor


Obviously gets :



ValueError: Error when checking input: expected input_5 to have 4 dimensions, but got array with shape (24, 1)


Here is my model code (it's basic out of the box)



#%%
train_labels=augmented_label
train_images=augmented_ims
# Importing the keras libraries
import keras
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D, Flatten, BatchNormalization, Activation, Dropout
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras.applications.inception_v3 import InceptionV3
# Pre-build model

base_model = InceptionV3(include_top = False, weights = None,)
# Adding output layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
output = Dense(units = 2, activation = 'sigmoid')(x)
# Creating the whole model
inception_model = Model(base_model.input, output)

# Summary of the model
#inception_model.summary()

# Compiling the model
inception_model.compile(optimizer = keras.optimizers.Adam(lr = 0.001),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
#%%
from keras.utils.np_utils import to_categorical
train_labels=to_categorical(np.asarray(augmented_label))
train_images=augmented_ims
train_images=np.asarray(train_images)
train_images=train_images/255
inception_model.fit(train_images, train_labels, epochs=5)


Thx










share|improve this question











$endgroup$











  • $begingroup$
    Can you post your model's code?
    $endgroup$
    – Shubham Panchal
    yesterday










  • $begingroup$
    I edited my post but I run very correctly when I run the session to have arrays.
    $endgroup$
    – Florian Laborde
    yesterday










  • $begingroup$
    Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
    $endgroup$
    – Florian Laborde
    yesterday















0












$begingroup$


This is probably a very stupid question but the regular confusion of arrays and tensors in speech makes me unable to find any answer on the net.



If have a samples long array of "tensorflow.python.framework.ops.Tensor" which are indeed correct numpy arrays of size (299,299,3) once evaluated. My model (inceptionv3) accepts default input of size (299,299,3). Why does it only recognize my input as a (samples, 1) array ? Do I really need to evaluate each tensor ? As evaluating one takes like 5s ...



How can I change the input of the model to get the model working ?
Or how can I change my tensors in a reasonable time to the right format?



I have :



train_images.shape Out[170]: (24,)


Precisely:



train_images
Out[167]:
[<tf.Tensor 'Squeeze_3:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_4:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_5:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_6:0' shape=(299, 299, 3) dtype=float32>,



And:



type(train_images[1]) Out[168]: tensorflow.python.framework.ops.Tensor


Obviously gets :



ValueError: Error when checking input: expected input_5 to have 4 dimensions, but got array with shape (24, 1)


Here is my model code (it's basic out of the box)



#%%
train_labels=augmented_label
train_images=augmented_ims
# Importing the keras libraries
import keras
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D, Flatten, BatchNormalization, Activation, Dropout
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras.applications.inception_v3 import InceptionV3
# Pre-build model

base_model = InceptionV3(include_top = False, weights = None,)
# Adding output layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
output = Dense(units = 2, activation = 'sigmoid')(x)
# Creating the whole model
inception_model = Model(base_model.input, output)

# Summary of the model
#inception_model.summary()

# Compiling the model
inception_model.compile(optimizer = keras.optimizers.Adam(lr = 0.001),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
#%%
from keras.utils.np_utils import to_categorical
train_labels=to_categorical(np.asarray(augmented_label))
train_images=augmented_ims
train_images=np.asarray(train_images)
train_images=train_images/255
inception_model.fit(train_images, train_labels, epochs=5)


Thx










share|improve this question











$endgroup$











  • $begingroup$
    Can you post your model's code?
    $endgroup$
    – Shubham Panchal
    yesterday










  • $begingroup$
    I edited my post but I run very correctly when I run the session to have arrays.
    $endgroup$
    – Florian Laborde
    yesterday










  • $begingroup$
    Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
    $endgroup$
    – Florian Laborde
    yesterday













0












0








0





$begingroup$


This is probably a very stupid question but the regular confusion of arrays and tensors in speech makes me unable to find any answer on the net.



If have a samples long array of "tensorflow.python.framework.ops.Tensor" which are indeed correct numpy arrays of size (299,299,3) once evaluated. My model (inceptionv3) accepts default input of size (299,299,3). Why does it only recognize my input as a (samples, 1) array ? Do I really need to evaluate each tensor ? As evaluating one takes like 5s ...



How can I change the input of the model to get the model working ?
Or how can I change my tensors in a reasonable time to the right format?



I have :



train_images.shape Out[170]: (24,)


Precisely:



train_images
Out[167]:
[<tf.Tensor 'Squeeze_3:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_4:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_5:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_6:0' shape=(299, 299, 3) dtype=float32>,



And:



type(train_images[1]) Out[168]: tensorflow.python.framework.ops.Tensor


Obviously gets :



ValueError: Error when checking input: expected input_5 to have 4 dimensions, but got array with shape (24, 1)


Here is my model code (it's basic out of the box)



#%%
train_labels=augmented_label
train_images=augmented_ims
# Importing the keras libraries
import keras
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D, Flatten, BatchNormalization, Activation, Dropout
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras.applications.inception_v3 import InceptionV3
# Pre-build model

base_model = InceptionV3(include_top = False, weights = None,)
# Adding output layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
output = Dense(units = 2, activation = 'sigmoid')(x)
# Creating the whole model
inception_model = Model(base_model.input, output)

# Summary of the model
#inception_model.summary()

# Compiling the model
inception_model.compile(optimizer = keras.optimizers.Adam(lr = 0.001),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
#%%
from keras.utils.np_utils import to_categorical
train_labels=to_categorical(np.asarray(augmented_label))
train_images=augmented_ims
train_images=np.asarray(train_images)
train_images=train_images/255
inception_model.fit(train_images, train_labels, epochs=5)


Thx










share|improve this question











$endgroup$




This is probably a very stupid question but the regular confusion of arrays and tensors in speech makes me unable to find any answer on the net.



If have a samples long array of "tensorflow.python.framework.ops.Tensor" which are indeed correct numpy arrays of size (299,299,3) once evaluated. My model (inceptionv3) accepts default input of size (299,299,3). Why does it only recognize my input as a (samples, 1) array ? Do I really need to evaluate each tensor ? As evaluating one takes like 5s ...



How can I change the input of the model to get the model working ?
Or how can I change my tensors in a reasonable time to the right format?



I have :



train_images.shape Out[170]: (24,)


Precisely:



train_images
Out[167]:
[<tf.Tensor 'Squeeze_3:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_4:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_5:0' shape=(299, 299, 3) dtype=float32>,
<tf.Tensor 'Squeeze_6:0' shape=(299, 299, 3) dtype=float32>,



And:



type(train_images[1]) Out[168]: tensorflow.python.framework.ops.Tensor


Obviously gets :



ValueError: Error when checking input: expected input_5 to have 4 dimensions, but got array with shape (24, 1)


Here is my model code (it's basic out of the box)



#%%
train_labels=augmented_label
train_images=augmented_ims
# Importing the keras libraries
import keras
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D, Flatten, BatchNormalization, Activation, Dropout
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras.applications.inception_v3 import InceptionV3
# Pre-build model

base_model = InceptionV3(include_top = False, weights = None,)
# Adding output layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
output = Dense(units = 2, activation = 'sigmoid')(x)
# Creating the whole model
inception_model = Model(base_model.input, output)

# Summary of the model
#inception_model.summary()

# Compiling the model
inception_model.compile(optimizer = keras.optimizers.Adam(lr = 0.001),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
#%%
from keras.utils.np_utils import to_categorical
train_labels=to_categorical(np.asarray(augmented_label))
train_images=augmented_ims
train_images=np.asarray(train_images)
train_images=train_images/255
inception_model.fit(train_images, train_labels, epochs=5)


Thx







keras tensorflow






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







Florian Laborde

















asked yesterday









Florian LabordeFlorian Laborde

153




153











  • $begingroup$
    Can you post your model's code?
    $endgroup$
    – Shubham Panchal
    yesterday










  • $begingroup$
    I edited my post but I run very correctly when I run the session to have arrays.
    $endgroup$
    – Florian Laborde
    yesterday










  • $begingroup$
    Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
    $endgroup$
    – Florian Laborde
    yesterday
















  • $begingroup$
    Can you post your model's code?
    $endgroup$
    – Shubham Panchal
    yesterday










  • $begingroup$
    I edited my post but I run very correctly when I run the session to have arrays.
    $endgroup$
    – Florian Laborde
    yesterday










  • $begingroup$
    Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
    $endgroup$
    – Florian Laborde
    yesterday















$begingroup$
Can you post your model's code?
$endgroup$
– Shubham Panchal
yesterday




$begingroup$
Can you post your model's code?
$endgroup$
– Shubham Panchal
yesterday












$begingroup$
I edited my post but I run very correctly when I run the session to have arrays.
$endgroup$
– Florian Laborde
yesterday




$begingroup$
I edited my post but I run very correctly when I run the session to have arrays.
$endgroup$
– Florian Laborde
yesterday












$begingroup$
Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
$endgroup$
– Florian Laborde
yesterday




$begingroup$
Maybe my question doesn't make sense because tensors have to be run anyway at some point ? But I was hoping I could do the fitting on tensors to gain computation time (other wise it takes like 10hours to run)
$endgroup$
– Florian Laborde
yesterday










0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47474%2ftensor-input-in-keras-model-is-array-of-tensors-but-wont-agree-to-dimensions%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















draft saved

draft discarded
















































Thanks for contributing an answer to Data Science Stack Exchange!


  • 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.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47474%2ftensor-input-in-keras-model-is-array-of-tensors-but-wont-agree-to-dimensions%23new-answer', 'question_page');

);

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







Popular posts from this blog

Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High