Giter VIP home page Giter VIP logo

Comments (2)

ggegoge avatar ggegoge commented on May 18, 2024 1

same here. running this via the tweet package and got this traceback:

python3 tweet_generator.py

Traceback (most recent call last):
  File "tweet_generator.py", line 6, in <module>
    from textgenrnn import textgenrnn
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/textgenrnn/__init__.py", line 1, in <module>
    from .textgenrnn import textgenrnn
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/textgenrnn/textgenrnn.py", line 1, in <module>
    from tensorflow.keras.callbacks import LearningRateScheduler, Callback
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/keras/__init__.py", line 19, in <module>
    from . import datasets
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/keras/datasets/__init__.py", line 14, in <module>
    from . import imdb
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/keras/datasets/imdb/__init__.py", line 11, in <module>
    from tensorflow.python.keras.datasets.imdb import get_word_index
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/keras/datasets/imdb.py", line 25, in <module>
    from tensorflow.python.keras.preprocessing.sequence import _remove_long_seq
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/keras/preprocessing/__init__.py", line 26, in <module>
    from tensorflow.python.keras.preprocessing import image
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/keras/preprocessing/image.py", line 24, in <module>
    from keras_preprocessing import image
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras_preprocessing/image.py", line 20, in <module>
    backend = get_keras_submodule('backend')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras_preprocessing/__init__.py", line 24, in get_keras_submodule
    raise ImportError('You need to first `import keras` '
ImportError: You need to first `import keras` in order to use `keras_preprocessing`. For instance, you can do:

\```
import keras
from keras_preprocessing import image
\```

Or, preferably, this equivalent formulation:

\```
from keras import preprocessing
\```

any ideas how to resolve this?

edit: okay, updating tensor flow fixed that for me and then it turned into another issue #197 (for which a fix was provided fortunately)

from textgenrnn.

Lukious avatar Lukious commented on May 18, 2024

Hi, I have spent quite a lot of time solving this problem.

The problem was in keras_applications.

There is two possible way to face this error message:

  1. When the keras_applications library version is too old
  2. When keras_applications are new but having trouble with TensorFlow's keras_preprocessing library

Anyway it occurred by .json file we can solve this problem by reinstalling Tensorflow and Keras-related things but I know that this works heavily stressful.

This is my personal recommendation for this kind of errors.

  1. If you are sure that you installed Keras perfectly then just skipping its check process of Keras backend.

First, find your path of 'keras_applications' are installed (It might be in such 'C:\ProgramData\Anaconda3\Lib\site-packages' Or, just use 'pip show keras_applications')

And then, open (imagenet_utils.py) than edit it like this

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import keras
import json
import warnings
import numpy as np
from . import get_keras_submodule
from . import set_keras_submodules


backend = set_keras_submodules('backend')
backed = 'backend'
keras_utils = get_keras_submodule('utils')

CLASS_INDEX = None
CLASS_INDEX_PATH = ('https://s3.amazonaws.com/deep-learning-models/'
                   'image-models/imagenet_class_index.json')

# Global tensor of imagenet mean for preprocessing symbolic inputs
_IMAGENET_MEAN = None

...

It's just editing check flag rightly (It should be checked by Keras backend API but because of version issue it impossible to check automatically sometimes).

  1. This is possibly happening with the 'keras_preprocessing' library for the recent version (because some parts of 'keras_applications' are moved to 'keras_preprocessing) in this case you should edit the same parts on 'keras_preprocessing'

I know that this is not a perfect solution for the code, But it works okay temporarily.
(But I still highly recommend resetting your env..!)

from textgenrnn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.