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

Models - Cannot import name Applications #8

Open
taellinglin opened this issue May 23, 2022 · 2 comments
Open

Models - Cannot import name Applications #8

taellinglin opened this issue May 23, 2022 · 2 comments

Comments

@taellinglin
Copy link

I am using tensorflow-cpu 2.9 and am wondering about this...

PS C:\ai> python main.py -content_path './bases/Base01.png' -style_path './styles/Style01.png'
Traceback (most recent call last):
  File "C:\ai\main.py", line 32, in <module>
    import models
  File "C:\ai\models.py", line 30, in <module>
    from tensorflow.python.keras import applications
ImportError: cannot import name 'applications' from 'tensorflow.python.keras' (C:\Users\kazun\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\__init__.py)
@taellinglin
Copy link
Author

https://www.tensorflow.org/api_docs/python/tf/keras/applications?version=nightly

Here is what it should be I guess...it's detecting activations, but not applications

@taellinglin
Copy link
Author

I editted your code out for importing it and just wrote it in as:
tf.keras.applications
and
tf.keras.applications.VGG19
etc.

def get_vgg_layers(layer_names):
    vgg = tf.keras.applications.VGG19(include_top=False, weights='imagenet')
    vgg.trainable = False
    outputs = [vgg.get_layer(name).output for name in layer_names]
    model = models.Model([vgg.input], outputs)
    return model
def call(self, inputs, **kwargs):
        inputs = inputs * 255.0
        preprocessed_input = tf.keras.applications.vgg19.preprocess_input(inputs)
        outputs = self.vgg(preprocessed_input)
        style_outputs, content_outputs = (outputs[:self.num_style_layers],
                                          outputs[self.num_style_layers:])

        style_outputs = [
            calculate_gram_matrix(style_output) for style_output in style_outputs
        ]
        content = {
            content_name: value
            for content_name, value in zip(self.CONTENT_LAYERS, content_outputs)
        }
        style = {
            style_name: value
            for style_name, value in zip(self.STYLE_LAYERS, style_outputs)
        }
        return {'content': content, 'style': style}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant