Tensorflow slice(None, None, None))' is an invalid keyUnderstanding slice notationAdd new keys to a dictionary?Check if a given key already exists in a dictionaryPython `if x is not None` or `if not x is None`?How to remove a key from a Python dictionary?Using make_template() in TensorFlowSimple Feedforward Neural Network with TensorFlow won't learnAttempted to use a closed Sessiontensorflow feed list feature (multi-hot) to tf.estimatortflite outputs don't match with tensorflow outputs for conv2d_transpose

Who goes first? Person disembarking bus or the bicycle?

How do I talk to my wife about unrealistic expectations?

Where are the Wazirs?

How to evaluate the performance of open source solver?

What was the nature of the known bugs in the Space Shuttle software?

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

What are the consequences for a developed nation to not accept any refugee?

NOLOCK or Read Uncommitted locking / latching behaviours

Uniform initialization by tuple

Can you create a free-floating MASYU puzzle?

Can we share mixing jug/beaker for developer, fixer and stop bath?

Floating Pumice Road. Slab Size

Examples of machine learning applied to operations research?

Why do airports remove/realign runways?

I'm feeling like my character doesn't fit the campaign

What is the meaning of "prairie-dog" in this sentence?

What was the significance of Spider-Man: Far From Home being an MCU Phase 3 film instead of a Phase 4 film?

Sense of humor in your sci-fi stories

How should I ask for a "pint" in countries that use metric?

What is the shape of the upper boundary of water hitting a screen?

How was the website able to tell my credit card was wrong before it processed it?

When is one 'Ready' to make Original Contributions to Mathematics?

Examples of fluid (including air) being used to transmit digital data?

What exactly is a "murder hobo"?



Tensorflow slice(None, None, None))' is an invalid key


Understanding slice notationAdd new keys to a dictionary?Check if a given key already exists in a dictionaryPython `if x is not None` or `if not x is None`?How to remove a key from a Python dictionary?Using make_template() in TensorFlowSimple Feedforward Neural Network with TensorFlow won't learnAttempted to use a closed Sessiontensorflow feed list feature (multi-hot) to tf.estimatortflite outputs don't match with tensorflow outputs for conv2d_transpose






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm implementing a regression model in tensorflow DNN framework which takes input of shape (1504924, 127) and predicts the value corresponding (of shape (1504924,1).



Following is my network



class q_model:
def __init__(self,
sess,
quantiles,
in_shape=127,
out_shape=1,
batch_size=32):

self.sess = sess

self.quantiles = quantiles
self.num_quantiles = len(quantiles)

self.in_shape = in_shape
self.out_shape = out_shape
self.batch_size = batch_size

self.outputs = []
self.losses = []
self.loss_history = []

self.build_model()
print("Completed")

def build_model(self, scope='q_model', reuse=tf.AUTO_REUSE):
with tf.variable_scope(scope, reuse=reuse) as scope:
self.x = tf.placeholder(tf.float32, shape=(None, self.in_shape,1))
self.y = tf.placeholder(tf.float32, shape=(None, self.out_shape))

self.layer0 = tf.layers.dense(self.x,
units=32,
activation=tf.nn.relu)
self.layer1 = tf.layers.dense(self.layer0,
units=32,
activation=tf.nn.relu)

# Create outputs and losses for all quantiles
for i in range(self.num_quantiles):
q = self.quantiles[i]

# Get output layers
output = tf.layers.dense(self.layer1, 1, name="_q".format(i, int(q*100)))
self.outputs.append(output)

# Create losses

error = tf.subtract(self.y, output)
loss = tf.reduce_mean(tf.maximum(q*error, (q-1)*error), axis=-1)

self.losses.append(loss)

# Create combined loss
self.combined_loss = tf.reduce_mean(tf.add_n(self.losses))
self.train_step = tf.train.AdamOptimizer().minimize(self.combined_loss)
print("Completed")

def fit(self, x, y, epochs=100):
for epoch in range(epochs):
epoch_losses = []
for idx in range(0, x.shape[1], self.batch_size):
batch_x = x[idx : min(idx + self.batch_size, x.shape[1]),:]
batch_y = y[idx : min(idx + self.batch_size, y.shape[1]),:]

feed_dict = self.x: batch_x,
self.y: batch_y

_, c_loss = self.sess.run([self.train_step, self.combined_loss], feed_dict)
epoch_losses.append(c_loss)

epoch_loss = np.mean(epoch_losses)
self.loss_history.append(epoch_loss)
if epoch % 100 == 0:
print("Epoch : ".format(epoch, epoch_loss))
print("Completed")

def predict(self, x):
# Run model to get outputs
feed_dict = self.x: x
predictions = sess.run(self.outputs, feed_dict)

return predictions


The model complies fine but I'm getting the following error when I try to fit the model



TypeError: '(slice(0, 32, None), slice(None, None, None))' is an invalid key


I'm unable to figure out where I'm missing. Appreciate any input.










share|improve this question






















  • where / how are you calling fit? Need an minimal reproducible example.

    – MFisherKDX
    Mar 25 at 21:21












  • your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

    – MFisherKDX
    Mar 25 at 21:24












  • Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

    – iprof0214
    Mar 25 at 21:53

















2















I'm implementing a regression model in tensorflow DNN framework which takes input of shape (1504924, 127) and predicts the value corresponding (of shape (1504924,1).



Following is my network



class q_model:
def __init__(self,
sess,
quantiles,
in_shape=127,
out_shape=1,
batch_size=32):

self.sess = sess

self.quantiles = quantiles
self.num_quantiles = len(quantiles)

self.in_shape = in_shape
self.out_shape = out_shape
self.batch_size = batch_size

self.outputs = []
self.losses = []
self.loss_history = []

self.build_model()
print("Completed")

def build_model(self, scope='q_model', reuse=tf.AUTO_REUSE):
with tf.variable_scope(scope, reuse=reuse) as scope:
self.x = tf.placeholder(tf.float32, shape=(None, self.in_shape,1))
self.y = tf.placeholder(tf.float32, shape=(None, self.out_shape))

self.layer0 = tf.layers.dense(self.x,
units=32,
activation=tf.nn.relu)
self.layer1 = tf.layers.dense(self.layer0,
units=32,
activation=tf.nn.relu)

# Create outputs and losses for all quantiles
for i in range(self.num_quantiles):
q = self.quantiles[i]

# Get output layers
output = tf.layers.dense(self.layer1, 1, name="_q".format(i, int(q*100)))
self.outputs.append(output)

# Create losses

error = tf.subtract(self.y, output)
loss = tf.reduce_mean(tf.maximum(q*error, (q-1)*error), axis=-1)

self.losses.append(loss)

# Create combined loss
self.combined_loss = tf.reduce_mean(tf.add_n(self.losses))
self.train_step = tf.train.AdamOptimizer().minimize(self.combined_loss)
print("Completed")

def fit(self, x, y, epochs=100):
for epoch in range(epochs):
epoch_losses = []
for idx in range(0, x.shape[1], self.batch_size):
batch_x = x[idx : min(idx + self.batch_size, x.shape[1]),:]
batch_y = y[idx : min(idx + self.batch_size, y.shape[1]),:]

feed_dict = self.x: batch_x,
self.y: batch_y

_, c_loss = self.sess.run([self.train_step, self.combined_loss], feed_dict)
epoch_losses.append(c_loss)

epoch_loss = np.mean(epoch_losses)
self.loss_history.append(epoch_loss)
if epoch % 100 == 0:
print("Epoch : ".format(epoch, epoch_loss))
print("Completed")

def predict(self, x):
# Run model to get outputs
feed_dict = self.x: x
predictions = sess.run(self.outputs, feed_dict)

return predictions


The model complies fine but I'm getting the following error when I try to fit the model



TypeError: '(slice(0, 32, None), slice(None, None, None))' is an invalid key


I'm unable to figure out where I'm missing. Appreciate any input.










share|improve this question






















  • where / how are you calling fit? Need an minimal reproducible example.

    – MFisherKDX
    Mar 25 at 21:21












  • your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

    – MFisherKDX
    Mar 25 at 21:24












  • Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

    – iprof0214
    Mar 25 at 21:53













2












2








2








I'm implementing a regression model in tensorflow DNN framework which takes input of shape (1504924, 127) and predicts the value corresponding (of shape (1504924,1).



Following is my network



class q_model:
def __init__(self,
sess,
quantiles,
in_shape=127,
out_shape=1,
batch_size=32):

self.sess = sess

self.quantiles = quantiles
self.num_quantiles = len(quantiles)

self.in_shape = in_shape
self.out_shape = out_shape
self.batch_size = batch_size

self.outputs = []
self.losses = []
self.loss_history = []

self.build_model()
print("Completed")

def build_model(self, scope='q_model', reuse=tf.AUTO_REUSE):
with tf.variable_scope(scope, reuse=reuse) as scope:
self.x = tf.placeholder(tf.float32, shape=(None, self.in_shape,1))
self.y = tf.placeholder(tf.float32, shape=(None, self.out_shape))

self.layer0 = tf.layers.dense(self.x,
units=32,
activation=tf.nn.relu)
self.layer1 = tf.layers.dense(self.layer0,
units=32,
activation=tf.nn.relu)

# Create outputs and losses for all quantiles
for i in range(self.num_quantiles):
q = self.quantiles[i]

# Get output layers
output = tf.layers.dense(self.layer1, 1, name="_q".format(i, int(q*100)))
self.outputs.append(output)

# Create losses

error = tf.subtract(self.y, output)
loss = tf.reduce_mean(tf.maximum(q*error, (q-1)*error), axis=-1)

self.losses.append(loss)

# Create combined loss
self.combined_loss = tf.reduce_mean(tf.add_n(self.losses))
self.train_step = tf.train.AdamOptimizer().minimize(self.combined_loss)
print("Completed")

def fit(self, x, y, epochs=100):
for epoch in range(epochs):
epoch_losses = []
for idx in range(0, x.shape[1], self.batch_size):
batch_x = x[idx : min(idx + self.batch_size, x.shape[1]),:]
batch_y = y[idx : min(idx + self.batch_size, y.shape[1]),:]

feed_dict = self.x: batch_x,
self.y: batch_y

_, c_loss = self.sess.run([self.train_step, self.combined_loss], feed_dict)
epoch_losses.append(c_loss)

epoch_loss = np.mean(epoch_losses)
self.loss_history.append(epoch_loss)
if epoch % 100 == 0:
print("Epoch : ".format(epoch, epoch_loss))
print("Completed")

def predict(self, x):
# Run model to get outputs
feed_dict = self.x: x
predictions = sess.run(self.outputs, feed_dict)

return predictions


The model complies fine but I'm getting the following error when I try to fit the model



TypeError: '(slice(0, 32, None), slice(None, None, None))' is an invalid key


I'm unable to figure out where I'm missing. Appreciate any input.










share|improve this question














I'm implementing a regression model in tensorflow DNN framework which takes input of shape (1504924, 127) and predicts the value corresponding (of shape (1504924,1).



Following is my network



class q_model:
def __init__(self,
sess,
quantiles,
in_shape=127,
out_shape=1,
batch_size=32):

self.sess = sess

self.quantiles = quantiles
self.num_quantiles = len(quantiles)

self.in_shape = in_shape
self.out_shape = out_shape
self.batch_size = batch_size

self.outputs = []
self.losses = []
self.loss_history = []

self.build_model()
print("Completed")

def build_model(self, scope='q_model', reuse=tf.AUTO_REUSE):
with tf.variable_scope(scope, reuse=reuse) as scope:
self.x = tf.placeholder(tf.float32, shape=(None, self.in_shape,1))
self.y = tf.placeholder(tf.float32, shape=(None, self.out_shape))

self.layer0 = tf.layers.dense(self.x,
units=32,
activation=tf.nn.relu)
self.layer1 = tf.layers.dense(self.layer0,
units=32,
activation=tf.nn.relu)

# Create outputs and losses for all quantiles
for i in range(self.num_quantiles):
q = self.quantiles[i]

# Get output layers
output = tf.layers.dense(self.layer1, 1, name="_q".format(i, int(q*100)))
self.outputs.append(output)

# Create losses

error = tf.subtract(self.y, output)
loss = tf.reduce_mean(tf.maximum(q*error, (q-1)*error), axis=-1)

self.losses.append(loss)

# Create combined loss
self.combined_loss = tf.reduce_mean(tf.add_n(self.losses))
self.train_step = tf.train.AdamOptimizer().minimize(self.combined_loss)
print("Completed")

def fit(self, x, y, epochs=100):
for epoch in range(epochs):
epoch_losses = []
for idx in range(0, x.shape[1], self.batch_size):
batch_x = x[idx : min(idx + self.batch_size, x.shape[1]),:]
batch_y = y[idx : min(idx + self.batch_size, y.shape[1]),:]

feed_dict = self.x: batch_x,
self.y: batch_y

_, c_loss = self.sess.run([self.train_step, self.combined_loss], feed_dict)
epoch_losses.append(c_loss)

epoch_loss = np.mean(epoch_losses)
self.loss_history.append(epoch_loss)
if epoch % 100 == 0:
print("Epoch : ".format(epoch, epoch_loss))
print("Completed")

def predict(self, x):
# Run model to get outputs
feed_dict = self.x: x
predictions = sess.run(self.outputs, feed_dict)

return predictions


The model complies fine but I'm getting the following error when I try to fit the model



TypeError: '(slice(0, 32, None), slice(None, None, None))' is an invalid key


I'm unable to figure out where I'm missing. Appreciate any input.







python tensorflow neural-network deep-learning






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 21:13









iprof0214iprof0214

1461 silver badge12 bronze badges




1461 silver badge12 bronze badges












  • where / how are you calling fit? Need an minimal reproducible example.

    – MFisherKDX
    Mar 25 at 21:21












  • your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

    – MFisherKDX
    Mar 25 at 21:24












  • Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

    – iprof0214
    Mar 25 at 21:53

















  • where / how are you calling fit? Need an minimal reproducible example.

    – MFisherKDX
    Mar 25 at 21:21












  • your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

    – MFisherKDX
    Mar 25 at 21:24












  • Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

    – iprof0214
    Mar 25 at 21:53
















where / how are you calling fit? Need an minimal reproducible example.

– MFisherKDX
Mar 25 at 21:21






where / how are you calling fit? Need an minimal reproducible example.

– MFisherKDX
Mar 25 at 21:21














your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

– MFisherKDX
Mar 25 at 21:24






your feed_dict argument in fit needs to map tensors self.x and self.y to numpy arrays. it looks like you are trying to map these tensors to tensors instead of arrays.

– MFisherKDX
Mar 25 at 21:24














Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

– iprof0214
Mar 25 at 21:53





Thanks, I reshaped the input as follows : # Reshape to input format for network X_train_rs = np.expand_dims(X_train.values, 1) y_train_rs = np.expand_dims(y_train.values, 1) Now I'm getting the error ValueError: Cannot feed value of shape (32, 1, 127) for Tensor 'q_model_23/Placeholder:0', which has shape '(?, 127, 1)'

– iprof0214
Mar 25 at 21:53












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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346482%2ftensorflow-slicenone-none-none-is-an-invalid-key%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




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346482%2ftensorflow-slicenone-none-none-is-an-invalid-key%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript