payload: {"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/31609","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/31609/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/31609/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/31609/events","html_url":"https://github.com/tensorflow/tensorflow/issues/31609","id":480542798,"node_id":"MDU6SXNzdWU0ODA1NDI3OTg=","number":31609,"title":"\"Init node weights/Assign doesn't exist in graph\" happens when use convert in tflite","user":{"login":"mmmmayi","id":24267342,"node_id":"MDQ6VXNlcjI0MjY3MzQy","avatar_url":"https://avatars0.githubusercontent.com/u/24267342?v=4","gravatar_id":"","url":"https://api.github.com/users/mmmmayi","html_url":"https://github.com/mmmmayi","followers_url":"https://api.github.com/users/mmmmayi/followers","following_url":"https://api.github.com/users/mmmmayi/following{/other_user}","gists_url":"https://api.github.com/users/mmmmayi/gists{/gist_id}","starred_url":"https://api.github.com/users/mmmmayi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmmmayi/subscriptions","organizations_url":"https://api.github.com/users/mmmmayi/orgs","repos_url":"https://api.github.com/users/mmmmayi/repos","events_url":"https://api.github.com/users/mmmmayi/events{/privacy}","received_events_url":"https://api.github.com/users/mmmmayi/received_events","type":"User","site_admin":false},"labels":[{"id":1445545631,"node_id":"MDU6TGFiZWwxNDQ1NTQ1NjMx","url":"https://api.github.com/repos/tensorflow/tensorflow/labels/TF%201.14","name":"TF 1.14","color":"5319e7","default":false},{"id":1097545273,"node_id":"MDU6TGFiZWwxMDk3NTQ1Mjcz","url":"https://api.github.com/repos/tensorflow/tensorflow/labels/comp:grappler","name":"comp:grappler","color":"0052cc","default":false},{"id":750616506,"node_id":"MDU6TGFiZWw3NTA2MTY1MDY=","url":"https://api.github.com/repos/tensorflow/tensorflow/labels/comp:lite","name":"comp:lite","color":"0052cc","default":false},{"id":473172988,"node_id":"MDU6TGFiZWw0NzMxNzI5ODg=","url":"https://api.github.com/repos/tensorflow/tensorflow/labels/type:bug","name":"type:bug","color":"159b2e","default":false}],"state":"open","locked":false,"assignee":{"login":"jvishnuvardhan","id":46058173,"node_id":"MDQ6VXNlcjQ2MDU4MTcz","avatar_url":"https://avatars2.githubusercontent.com/u/46058173?v=4","gravatar_id":"","url":"https://api.github.com/users/jvishnuvardhan","html_url":"https://github.com/jvishnuvardhan","followers_url":"https://api.github.com/users/jvishnuvardhan/followers","following_url":"https://api.github.com/users/jvishnuvardhan/following{/other_user}","gists_url":"https://api.github.com/users/jvishnuvardhan/gists{/gist_id}","starred_url":"https://api.github.com/users/jvishnuvardhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvishnuvardhan/subscriptions","organizations_url":"https://api.github.com/users/jvishnuvardhan/orgs","repos_url":"https://api.github.com/users/jvishnuvardhan/repos","events_url":"https://api.github.com/users/jvishnuvardhan/events{/privacy}","received_events_url":"https://api.github.com/users/jvishnuvardhan/received_events","type":"User","site_admin":false},"assignees":[{"login":"jvishnuvardhan","id":46058173,"node_id":"MDQ6VXNlcjQ2MDU4MTcz","avatar_url":"https://avatars2.githubusercontent.com/u/46058173?v=4","gravatar_id":"","url":"https://api.github.com/users/jvishnuvardhan","html_url":"https://github.com/jvishnuvardhan","followers_url":"https://api.github.com/users/jvishnuvardhan/followers","following_url":"https://api.github.com/users/jvishnuvardhan/following{/other_user}","gists_url":"https://api.github.com/users/jvishnuvardhan/gists{/gist_id}","starred_url":"https://api.github.com/users/jvishnuvardhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvishnuvardhan/subscriptions","organizations_url":"https://api.github.com/users/jvishnuvardhan/orgs","repos_url":"https://api.github.com/users/jvishnuvardhan/repos","events_url":"https://api.github.com/users/jvishnuvardhan/events{/privacy}","received_events_url":"https://api.github.com/users/jvishnuvardhan/received_events","type":"User","site_admin":false}],"milestone":null,"comments":15,"created_at":"2019-08-14T08:15:50Z","updated_at":"2019-10-22T03:17:23Z","closed_at":null,"author_association":"NONE","body":"**System information**\r\n- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Linux Ubuntu 18.04\r\n- TensorFlow installed from (source or binary):\r\n- TensorFlow version: Tensorflow nightly\r\n- Python version: 3.6\r\n- Installed using virtualenv? pip? conda?: pip\r\n- CUDA/cuDNN version: 7/10\r\n\r\n**Describe the problem**\r\nWhen I tried to convert a TensorFlow GraphDef into a TensorFlow Lite FlatBuffer from a tf.Session object, a error happend such like this:\r\n`2019-08-14 16:01:23.946453: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session\r\n2019-08-14 16:01:23.947157: E tensorflow/core/grappler/grappler_item_builder.cc:656] Init node weights/Assign doesn't exist in graph\r\n`\r\nand my code all showed below:\r\n\r\n\r\n    def main(_):\r\n\r\n      def loss_function(weight, logits, labels):\r\n        labels = tf.one_hot(labels,4)\r\n        labels = tf.cast(labels, tf.float32)\r\n        first = tf.reduce_sum(tf.multiply(-labels, logits),1)\r\n        second_0 = tf.add(tf.exp(logits[:,0]),tf.exp(logits[:,1]))\r\n        second_1 = tf.add(tf.exp(logits[:,2]),tf.exp(logits[:,3]))\r\n        log = tf.log(tf.add(second_1,second_0))\r\n        weight = tf.transpose(tf.reduce_sum(tf.multiply(labels, weight),1))\r\n        output = tf.multiply(weight,tf.add(first,log))\r\n\r\n        return output\r\n\r\n      def normalize(stft):\r\n        stft_1 = numpy.empty([stft.shape[0],128,128])\r\n        stft_2 = numpy.empty([stft_1.shape[0],stft_1.shape[1],stft_1.shape[2],1])\r\n        for i in range(stft_1.shape[0]):\r\n          image = Image.fromarray(stft[i,:,:])\r\n          image = image.resize([128,128])\r\n          stft_1[i,:,:] = numpy.array(image)\r\n\r\n          min = numpy.min(stft_1[i,:,:])\r\n          max = numpy.max(stft_1[i,:,:])\r\n          stft_1[i,:,:] = (stft_1[i,:,:]-min)/(max-min)\r\n          stft_2[i,:,:,:] = stft_1[i,:,:].reshape((stft_1.shape[1],stft_1.shape[2],1))\r\n        return stft_2  \r\n    # Get the data.\r\n    \r\n    stft_training, mfcc_training, labels_training = joblib.load(open(FLAGS.input, mode='rb'))\r\n    stft_test, mfcc_test, labels_test = joblib.load(open(FLAGS.test, mode='rb'))\r\n\r\n    stft_test = numpy.array(stft_test)\r\n    mfcc_test = numpy.array(mfcc_test)\r\n    labels_test = numpy.array(labels_test)\r\n    stft_test = normalize(stft_test)\r\n    mfcc_test = normalize(mfcc_test)\r\n\r\n    stft_training = numpy.array(stft_training)\r\n    mfcc_training = numpy.array(mfcc_training)\r\n    labels_training = numpy.array(labels_training)\r\n    stft_training = normalize(stft_training)\r\n    mfcc_training = normalize(mfcc_training)\r\n\r\n    stft_shape = stft_training.shape\r\n    stft_shape = (None, stft_shape[1], stft_shape[2], 1)\r\n\r\n    mfcc_shape = mfcc_training.shape\r\n    mfcc_shape = (None, mfcc_shape[1], mfcc_shape[2], 1)\r\n\r\n    labels_shape = labels_training.shape\r\n    labels_shape = (None)\r\n\r\n    stft_placeholder = tf.placeholder(stft_training.dtype, stft_shape)\r\n    labels_placeholder = tf.placeholder(labels_training.dtype, labels_shape)\r\n    mfcc_placeholder = tf.placeholder(mfcc_training.dtype, mfcc_shape)\r\n    \r\n    dataset_training = tf.data.Dataset.from_tensor_slices((stft_placeholder, mfcc_placeholder, labels_placeholder))\r\n    dataset_training  = dataset_training.apply(\r\n        tf.data.experimental.shuffle_and_repeat(len(stft_training), None))  \r\n    dataset_training  = dataset_training.batch(BATCH_SIZE)\r\n    dataset_training  = dataset_training.prefetch(1)\r\n    iterator_training = dataset_training.make_initializable_iterator()\r\n    next_element_training = iterator_training.get_next()\r\n    num_epochs = FLAGS.epochs\r\n\r\n      train_size = labels_training.shape[0]\r\n\r\n      with tf.name_scope('input'):\r\n        stft = tf.placeholder(\r\n            name=\"stft\",\r\n            dtype=data_type(),\r\n            shape=(BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS))\r\n        mfcc = tf.placeholder(\r\n            name=\"mfcc\",\r\n            dtype=data_type(),\r\n            shape=(BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS))\r\n        labels = tf.placeholder(tf.int64, shape=(BATCH_SIZE,))\r\n\r\n      with tf.name_scope('test_input'):\r\n        stft_t = tf.placeholder(\r\n            data_type(),\r\n            shape=(EVAL_BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS))\r\n        mfcc_t = tf.placeholder(\r\n            data_type(),\r\n            shape=(EVAL_BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS))\r\n\r\n      model = BRN()\r\n      logits = model.forward(stft, mfcc)\r\n      logits_ = tf.add(0.,logits,name=\"logits_\")\r\n      try:\r\n        scalar_summary = tf.scalar_summary\r\n        SummaryWrite = tf.train.SummaryWrite\r\n        merge_summary = tf.merge_summary\r\n      except:\r\n        scalar_summary = tf.summary.scalar\r\n        SummaryWrite = tf.summary.FileWriter\r\n        merge_summary = tf.summary.merge\r\n      with tf.name_scope('loss'):\r\n        weights = [1.0, 1.7, 4.1, 5.7]\r\n         mid = loss_function(weights, logits=logits, labels=labels)\r\n        loss = tf.reduce_sum(mid)\r\n    \r\n        loss_summary = scalar_summary('loss', loss)\r\n        regularizers = (tf.nn.l2_loss(model.conv1_weights) + tf.nn.l2_loss(model.conv2_weights) +\r\n                    tf.nn.l2_loss(model.fc_weights) + tf.nn.l2_loss(model.fc_biases))\r\n\r\n        batch = tf.Variable(0, dtype=data_type())\r\n \r\n      with tf.name_scope('train'):\r\n\r\n        optimizer = tf.train.AdamOptimizer(0.001).minimize(loss)\r\n      train_prediction = tf.nn.softmax(logits)\r\n      eval_prediction = tf.nn.softmax(model.forward(stft_t, mfcc_t))\r\n      start_time = time.time()\r\n\r\n      def eval_in_batches(stft_data, mfcc_data, sess, type):\r\n        size = stft_data.shape[0]\r\n        if size < EVAL_BATCH_SIZE:\r\n          raise ValueError(\"batch size for evals larger than dataset: %d\" % size)\r\n        predictions = numpy.ndarray(shape=(size, NUM_LABELS), dtype=numpy.float32)\r\n        for begin in xrange(0, size, EVAL_BATCH_SIZE):\r\n          end = begin + EVAL_BATCH_SIZE\r\n          if end <= size:\r\n            if type == 'train':\r\n              predictions[begin:end, :] = sess.run(\r\n                  train_prediction,\r\n                  feed_dict={stft: stft_data[begin:end, ...], mfcc: mfcc_data[begin:end, ...]})\r\n            else: \r\n              predictions[begin:end, :] = sess.run(\r\n                  eval_prediction,\r\n                  feed_dict={stft_t: stft_data[begin:end, ...], mfcc_t: mfcc_data[begin:end, ...]})\r\n          else:\r\n            if type == 'train':\r\n              batch_predictions = sess.run(\r\n                  train_prediction,\r\n                  feed_dict={stft: stft_data[-EVAL_BATCH_SIZE:, ...], mfcc: mfcc_data[-EVAL_BATCH_SIZE:, ...]})\r\n            else:\r\n               batch_predictions = sess.run(\r\n                  eval_prediction,\r\n                  feed_dict={stft_t: stft_data[-EVAL_BATCH_SIZE:, ...], mfcc_t: mfcc_data[-EVAL_BATCH_SIZE:, ...]})\r\n            predictions[begin:, :] = batch_predictions[begin - size:, :]\r\n        return predictions\r\n\r\n\r\n      config = tf.ConfigProto()\r\n      config.gpu_options.allow_growth = True  \r\n\r\n      with tf.Session(config=config) as sess:\r\n   \r\n        tf.global_variables_initializer().run()\r\n\r\n        merged = tf.summary.merge_all()\r\n        writer = SummaryWrite(FLAGS.logs + 'train', sess.graph)\r\n        sess.run(iterator_training.initializer, feed_dict={stft_placeholder:stft_training,\r\n                          mfcc_placeholder:mfcc_training,\r\n                         labels_placeholder:labels_training})\r\n\r\n        for step in xrange(int(num_epochs * train_size) // BATCH_SIZE):\r\n\r\n          batch_stft, batch_mfcc, batch_labels = sess.run(next_element_training)\r\n  \r\n          feed_dict = {stft: batch_stft,\r\n                       mfcc: batch_mfcc,\r\n                       labels: batch_labels}\r\n          sess.run(optimizer, feed_dict=feed_dict)\r\n          if step % EVAL_FREQUENCY == 0:\r\n\r\n        summary, l = sess.run([merged, loss],\r\n                                      feed_dict=feed_dict)\r\n            writer.add_summary(summary, step)\r\n            elapsed_time = time.time() - start_time\r\n            start_time = time.time()\r\n            rate, acc = error_rate(eval_in_batches(stft_training, mfcc_training, sess, 'train'), labels_training)\r\n            acc_summary = scalar_summary('accuracy', acc)\r\n            print('Step %d (epoch %.2f), Minibatch loss: %.3f, Minibatch error: %.1f%%, Accuracy:%.4f' %\r\n              (step, float(step) * BATCH_SIZE / train_size,\r\n              l,rate, acc))\r\n            sys.stdout.flush()\r\n            test_error, test_acc = error_rate(eval_in_batches(stft_test, mfcc_test, sess, 'test'), labels_test)\r\n            print('Testset error: %.1f%%, Accuracy:%.4f' % (test_error, test_acc))\r\n\r\n    converter = tf.lite.TFLiteConverter.from_session(sess, [stft,mfcc], [logits_])\r\n    tflite_model = converter.convert()\r\n    open(\"BRN.tflite\", \"wb\").write(tflite_model)\r\n        \r\n    writer.close()\r\n\r\nWhen I run the official demo of converting a TensorFlow GraphDef into a TensorFlow Lite FlatBuffer from a tf.Session object, the error also happens. Does that ok? I mean, can I use the weight trained in TensorFlow Lite? or the file doesn't save the weight?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/544789881","html_url":"https://github.com/tensorflow/tensorflow/issues/31609#issuecomment-544789881","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/31609","id":544789881,"node_id":"MDEyOklzc3VlQ29tbWVudDU0NDc4OTg4MQ==","user":{"login":"mmmmayi","id":24267342,"node_id":"MDQ6VXNlcjI0MjY3MzQy","avatar_url":"https://avatars0.githubusercontent.com/u/24267342?v=4","gravatar_id":"","url":"https://api.github.com/users/mmmmayi","html_url":"https://github.com/mmmmayi","followers_url":"https://api.github.com/users/mmmmayi/followers","following_url":"https://api.github.com/users/mmmmayi/following{/other_user}","gists_url":"https://api.github.com/users/mmmmayi/gists{/gist_id}","starred_url":"https://api.github.com/users/mmmmayi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmmmayi/subscriptions","organizations_url":"https://api.github.com/users/mmmmayi/orgs","repos_url":"https://api.github.com/users/mmmmayi/repos","events_url":"https://api.github.com/users/mmmmayi/events{/privacy}","received_events_url":"https://api.github.com/users/mmmmayi/received_events","type":"User","site_admin":false},"created_at":"2019-10-22T03:17:23Z","updated_at":"2019-10-22T03:17:23Z","author_association":"NONE","body":"> @mmmmayi I am currently facing the same issue, have you found a solution ?\r\n> Thanks !\r\n\r\nhi, actually I didn't figure it out, but it seems have no effect to the result, because I can still get the tflite model even with this error"}}
other: {"actor":{"display_login":"mmmmayi"}}