Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TensorFlow1.5.0 absl.flags._exceptions.UnparsedFlagAccessError in Jupyter Notebook #3327

Closed
jhljx opened this issue Feb 11, 2018 · 2 comments
Milestone

Comments

@jhljx
Copy link

jhljx commented Feb 11, 2018

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 1.5.0
  • Python version: 3.6
  • Bazel version (if compiling from source): n/a
  • GCC/Compiler version (if compiling from source): n/a
  • CUDA/cuDNN version: 9.0/7.0.5
  • GPU model and memory:GeForce 950M(4Gb)
  • Exact command to reproduce:

Describe the problem

I run the function cifar10.maybe_download_and_extract() of tensorflow/models/tutorials/image/cifar10.py file in python command and jupyter notebook .The code runs successfully in python command, but it causes absl.flags._exceptions.UnparsedFlagAccessErrorfrom cifar10.FLAGS.data_dir in jupyter notebook.

The jupyter notebook has already configured the tensorflow kernel, other tensorflow examples could run smoothly on jupyter notebook.

Significant code in cifar10.py file is:

import tensorflow as tf
import cifar10_input
FLAGS = tf.app.flags.FLAGS

# Basic model parameters.
tf.app.flags.DEFINE_integer('batch_size', 128,
                        """Number of images to process in a batch.""")
tf.app.flags.DEFINE_string('data_dir', '/tmp/cifar10_data',
                       """Path to the CIFAR-10 data directory.""")
tf.app.flags.DEFINE_boolean('use_fp16', False,
                        """Train the model using fp16.""")
# .....
def maybe_download_and_extract():
    """Download and extract the tarball from Alex's website."""
    dest_directory = FLAGS.data_dir
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
# ......

The exception happened from the code statement dest_directory = FLAGS.data_dir.

The successful output in python command is as follows:

>>> cifar10.maybe_download_and_extract()
>> Downloading cifar-10-binary.tar.gz 100.0%
Successfully downloaded cifar-10-binary.tar.gz 170052171 bytes.

The detailed error in jupyter notebook is as follows:

UnrecognizedFlagError                     Traceback (most recent call last)
<ipython-input-6-ddaee26bfd14> in <module>()
----> 1 cifar10.maybe_download_and_extract()
~/models/tutorials/image/cifar10/cifar10.py in maybe_download_and_extract()
381 def maybe_download_and_extract():
382   """Download and extract the tarball from Alex's website."""
--> 383   dest_directory = FLAGS.data_dir
384   if not os.path.exists(dest_directory):
385     os.makedirs(dest_directory)
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/platform/flags.py in 
__getattr__(self, name)
82     # a flag.
83     if not wrapped.is_parsed():
---> 84       wrapped(_sys.argv)
85     return wrapped.__getattr__(name)
86 
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/absl/flags/_flagvalues.py in __call__(self, argv, known_only)
628       suggestions = _helpers.get_flag_suggestions(name, list(self))
629       raise _exceptions.UnrecognizedFlagError(
--> 630           name, value, suggestions=suggestions)
631 
632     self.mark_as_parsed()
UnrecognizedFlagError: Unknown command line flag 'f'

Source code / logs

#git clone https://github.com/tensorflow/models.git
#cd models/tutorials/image/cifar10
import cifar10
cifar10.maybe_download_and_extract()
@takluyver takluyver added this to the Reference milestone Feb 12, 2018
@takluyver
Copy link
Member

If that function is something you're meant to run from Python code, it shouldn't be looking at sys.argv. If you're meant to run the example as a script, try using %run .../cifar10.py.

@jtpio
Copy link
Member

jtpio commented Jun 21, 2023

Closing as answered by #3327 (comment), thanks!

@jtpio jtpio closed this as completed Jun 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants