question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrade to latest tensorpack dependency: DQN.py returning a 'NotImplementedError'

See original GitHub issue

Thanks for your project. I got some troubles when I tried to reproduce your example ‘LandmarkDetection’.

  1. When I execute the command with your default setting , I get an error listed below that I cannot solve it. My environment is
  • python 3.5.2
  • tensorflow 1.13.1 cpu version
  • tensorpack 0.9.4
  • Ubuntu 16.04.6 LTS
# command
python3 DQN.py --task train --algo DQN --files './data/filenames/image_files.txt' './data/filenames/landmark_files.txt'
# error
Traceback (most recent call last):
  File "DQN.py", line 263, in <module>
    launch_train_with_config(config, SimpleTrainer())
  File "/home/ty/.local/lib/python3.5/site-packages/tensorpack/train/interface.py", line 90, in launch_train_with_config
    model.get_input_signature(), input,
  File "/home/ty/.local/lib/python3.5/site-packages/tensorpack/utils/argtools.py", line 200, in wrapper
    value = func(*args, **kwargs)
  File "/home/ty/.local/lib/python3.5/site-packages/tensorpack/graph_builder/model_desc.py", line 92, in get_input_signature
    return [TensorSpec(shape=p.shape, dtype=p.dtype, name=get_op_tensor_name(p.name)[0]) for p in inputs]
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/ty/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5253, in get_controller
    yield g
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/ty/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5061, in get_controller
    yield default
  File "/home/ty/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5253, in get_controller
    yield g
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/ty/.local/lib/python3.5/site-packages/tensorflow/python/eager/context.py", line 415, in _mode
    yield
  File "/home/ty/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5253, in get_controller
    yield g
  File "/home/ty/.local/lib/python3.5/site-packages/tensorpack/graph_builder/model_desc.py", line 86, in get_input_signature
    inputs = self.inputs()
  File "/home/ty/.local/lib/python3.5/site-packages/tensorpack/graph_builder/model_desc.py", line 116, in inputs
    raise NotImplementedError()
NotImplementedError
  1. according to a tensorpack issue , get_tf_version_number was deprecated by tensorflow and you should useget_tf_version_tuple in your tensorpack-medical .

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
TianYang-TYcommented, May 17, 2019

@ArjitJ It’s actually a version mismatch issue. After re-installing tensorpack to 0.8.0, it works fine now.

1reaction
ppwwyyxxcommented, Jul 11, 2019

These are the changes needed to run “LandmarkDetection/DQN” with tensorpack master, following the tensorpack changelog:

diff --git i/examples/LandmarkDetection/DQN/DQNModel.py w/examples/LandmarkDetection/DQN/DQNModel.py
index d9a5bf5..3cd8e35 100644
--- i/examples/LandmarkDetection/DQN/DQNModel.py
+++ w/examples/LandmarkDetection/DQN/DQNModel.py
@@ -29,7 +29,7 @@ class Model2D(ModelDesc):
         self.image_shape = image_shape
         self.num_actions = num_actions
 
-    def _get_inputs(self):
+    def inputs(self):
         # Use a combined state for efficiency.
         # The first h channels are the current state, and the last h channels are the next state.
         return [InputDesc(tf.uint8,
@@ -48,7 +48,7 @@ class Model2D(ModelDesc):
     def get_DQN_prediction(self, image):
         return self._get_DQN_prediction(image)
 
-    def _build_graph(self, inputs):
+    def build_graph(self, *inputs):
         comb_state, action, reward, isOver = inputs
         comb_state = tf.cast(comb_state, tf.float32)
         state = tf.slice(comb_state, [0, 0, 0, 0], [-1, -1, -1, self.channel], name='state')
@@ -80,11 +80,12 @@ class Model2D(ModelDesc):
 
         target = reward + (1.0 - tf.cast(isOver, tf.float32)) * self.gamma * tf.stop_gradient(best_v)
 
-        self.cost = tf.losses.huber_loss(target, pred_action_value,
+        cost = tf.losses.huber_loss(target, pred_action_value,
                                          reduction=tf.losses.Reduction.MEAN)
         summary.add_param_summary(('conv.*/W', ['histogram', 'rms']),
                                   ('fc.*/W', ['histogram', 'rms']))   # monitor all W
-        summary.add_moving_summary(self.cost)
+        summary.add_moving_summary(cost)
+        return cost
 
     def _get_optimizer(self):
         lr = tf.get_variable('learning_rate',initializer=1e-3, trainable=False)
@@ -105,8 +106,8 @@ class Model2D(ModelDesc):
                 ops.append(v.assign(G.get_tensor_by_name(new_name + ':0')))
         return tf.group(*ops, name='update_target_network')
 
-    
-    
+
+
 class Model3D(ModelDesc):
     def __init__(self, image_shape, channel, method, num_actions, gamma):
         """
@@ -124,7 +125,7 @@ class Model3D(ModelDesc):
         self.image_shape = image_shape
         self.num_actions = num_actions
 
-    def _get_inputs(self):
+    def inputs(self):
         # Use a combined state for efficiency.
         # The first h channels are the current state, and the last h channels are the next state.
         return [InputDesc(tf.uint8,
@@ -144,7 +145,7 @@ class Model3D(ModelDesc):
     def get_DQN_prediction(self, image):
         return self._get_DQN_prediction(image)
 
-    def _build_graph(self, inputs):
+    def build_graph(self, *inputs):
         comb_state, action, reward, isOver = inputs
         comb_state = tf.cast(comb_state, tf.float32)
         state = tf.slice(comb_state, [0, 0, 0, 0, 0], [-1, -1, -1, -1, self.channel], name='state')
@@ -175,13 +176,14 @@ class Model3D(ModelDesc):
             best_v = tf.reduce_sum(targetQ_predict_value * predict_onehot, 1)
 
         target = reward + (1.0 - tf.cast(isOver, tf.float32)) * self.gamma * tf.stop_gradient(best_v)
-        self.cost = tf.losses.huber_loss(target, pred_action_value,
+        cost = tf.losses.huber_loss(target, pred_action_value,
                                          reduction=tf.losses.Reduction.MEAN)
         summary.add_param_summary(('conv.*/W', ['histogram', 'rms']),
                                   ('fc.*/W', ['histogram', 'rms']))  # monitor all W
-        summary.add_moving_summary(self.cost)
+        summary.add_moving_summary(cost)
+        return cost
 
-    def _get_optimizer(self):
+    def optimizer(self):
         lr = tf.get_variable('learning_rate', initializer=1e-3, trainable=False)
         opt = tf.train.AdamOptimizer(lr, epsilon=1e-3)
         return optimizer.apply_grad_processors(
diff --git i/tensorpack_medical/models/conv3d.py w/tensorpack_medical/models/conv3d.py
index 5560f65..7482641 100644
--- i/tensorpack_medical/models/conv3d.py
+++ w/tensorpack_medical/models/conv3d.py
@@ -1,12 +1,11 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # File: conv3d.py
-# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
 # Modified: Amir Alansary <amiralansary@gmail.com>
 
 import tensorflow as tf
 from tensorpack import layer_register, VariableHolder
-from tensorpack.tfutils.common import get_tf_version_number
+from tensorpack.tfutils.common import get_tf_version_tuple
 from .tflayer import rename_get_variable, convert_to_tflayer_args
 
 from tensorpack_medical.utils.argtools import shape3d, shape5d, get_data_format3d
@@ -84,14 +83,14 @@ def Conv3D(
 
         out_channel = filters
         assert out_channel % split == 0
-        assert dilation_rate == (1, 1, 1) or get_tf_version_number() >= 1.5, 'TF>=1.5 required for group dilated conv'
+        assert dilation_rate == (1, 1, 1) or get_tf_version_tuple() >= (1, 5), 'TF>=1.5 required for group dilated conv'
 
         kernel_shape = shape3d(kernel_size)
         filter_shape = kernel_shape + [in_channel / split, out_channel]
         stride = shape5d(strides, data_format=data_format)
 
         kwargs = dict(data_format=data_format)
-        if get_tf_version_number() >= 1.5:
+        if get_tf_version_tuple() >= (1, 5):
             kwargs['dilations'] = shape4d(dilation_rate, data_format=data_format)
 
         W = tf.get_variable(
diff --git i/tensorpack_medical/models/tflayer.py w/tensorpack_medical/models/tflayer.py
index f2ed0ad..7f58b80 100644
--- i/tensorpack_medical/models/tflayer.py
+++ w/tensorpack_medical/models/tflayer.py
@@ -8,7 +8,7 @@ import tensorflow as tf
 import six
 import functools
 
-from tensorpack.tfutils.common import get_tf_version_number
+from tensorpack.tfutils.common import get_tf_version_tuple
 from tensorpack.tfutils.varreplace import custom_getter_scope
 
 from tensorpack_medical.utils.argtools import get_data_format3d
@@ -89,7 +89,7 @@ def rename_get_variable(mapping):
 
 
 def monkeypatch_tf_layers():
-    if get_tf_version_number() < 1.4:
+    if get_tf_version_tuple() < (1, 4):
         if not hasattr(tf.layers, 'Dense'):
             from tensorflow.python.layers.core import Dense
             tf.layers.Dense = Dense
Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot import name 'get_tf_version_number' · Issue #1122
While running the below line: from tensorpack.tfutils.common import ... Upgrade to latest tensorpack dependency: DQN.py returning a ...
Read more >
Keras RL not implemented error from overwritten class ...
I've been working on an RL agent to do the Taxi problem in openai gym. I picked the DQNAgent from keras-rl and I...
Read more >
tensorpack
Tensorpack is a neural network training interface based on TensorFlow. ... process large datasets (e.g. ImageNet) in pure Python with autoparallelization.
Read more >
https://patch-diff.githubusercontent.com/raw/tenso...
With new unified backend between CPU and GPU mode, since the CuDNN kernel is ... + +This is not part of mixed_precision.py to...
Read more >
A Neural Net Training Interface on TensorFlow, with focus ...
Tensorpack is a neural network training interface based on TensorFlow. ReadTheDoc Gitter chat model-zoo. Features: It's Yet Another TF high-level API, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found