tensorflow-2-style-transfer
tensorflow-2-style-transfer copied to clipboard
Models - Cannot import name Applications
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)
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
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}