Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6392 Discussions

TypeError: 'NoneType' object is not subscriptable

idata
Employee
2,814 Views
System: Ubuntu 16.04 NCSDK version: 2.05 Python version: 3.5.2

 

Hi,

 

I'm running a linear regression example and trying to compile it for the NCS. I've pasted the code below. Tracking it through TensorFlowParser, I see:

 

     

  • node.inputs[0].name as x_input:0
  •  

  • strip_tensor_id(node.inputs[0].name)) as x_input
  •  

  • get_input(strip_tensor_id(node.inputs[0].name))) as None
  •  

 

Thanks for your help!

 

def model(X, w): return X * w X = tf.placeholder(tf.float64, shape=(None, 1), name="x_input") w = tf.Variable(np.zeros(1), name="weight") pred = model(X, w) if not args["infer"]: num_points = 101 trX = np.float64(np.linspace(-1,1,num_points)).reshape((num_points, 1)) trY = np.float64(2*trX + np.random.randn(*trX.shape) * 0.33).reshape((num_points, 1)) Y = tf.placeholder(tf.float64, shape=(None, 1)) output = tf.identity(pred) cost = tf.reduce_sum(tf.square(Y - pred)) saver = tf.train.Saver(tf.global_variables()) sess = tf.Session() train_op = tf.train.GradientDescentOptimizer(0.01).minimize(cost) init = tf.global_variables_initializer() sess.run(init) for i in range(100): sess.run(train_op, feed_dict={X:trX, Y:trY}) saver.save(sess, '/home/workspace/sandbox/simple_tf_test/lr') print(sess.run(w)) else: print('Inferring to save') output = tf.identity(pred, name="y_output") saver = tf.train.Saver(tf.global_variables()) sess = tf.Session() global_init = tf.global_variables_initializer() sess.run(global_init) local_init = tf.local_variables_initializer() sess.run(local_init) saver.restore(sess, '/home/workspace/sandbox/simple_tf_test/lr') saver.save(sess, '/home/workspace/sandbox/simple_tf_test/lr_graph')
0 Kudos
2 Replies
reekjohns
Beginner
2,272 Views

The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:

None[something]

This error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method . This is a design principle for all mutable data structures in Python.

 

0 Kudos
Courses
Beginner
2,055 Views

Nice to see your written post .

Visit here to know more information : typeerror nonetype object is not subscriptable

0 Kudos
Reply