Closed starboyvarun closed 3 years ago
Could you tell me which keras and tensorflow version you are using?
just because of this error I can't get forward. Please also add me to LinkedIn with the name Varun Allen. I really need to solve this bug by end of tomorrow. Thank You @wkopp
The keras/tensorflow versions are not compatible with the janggu version you are using. Try to follow the installation instructions on the readme page (https://github.com/BIMSBbioinfo/janggu#readme). As explained there, for tensorflow 2 you can use tensorflow==2.2 and keras==2.4.3
reading the readme page, I installed it showed the same version. And again gave the same error.
while using other commands in the readme page still its showing 2.6.0 version
Then the installation of the corresponding package versions seems to have failed, as is suggested by the conflict messages that you've posted above. Eventually you should have tensorflow==2.2 and keras==2.4.3 installed.
But I tried installing it. using the above command can you tell me what should I do now? how I can install tensorflow==2.2 and keras==2.4.3 without conflict? Thankyou.
Please note that these issues are not related to janggu, but to other packages (tensorflow and keras) and the particular environment and perhaps the google collab's specific settings that you use, which I am not familiar with. You could try uninstall and reinstall keras and tensorflow to see if you could overcome the package conflicts or try to use a fresh environment in which you don't get the conflicts.
insted of -- from keras.engine.topology import Layer -- try options 1 or 2
@anoopkdcs Thank you for replying. I already solved this issue. If you are using janggu in google collab and facing any issue let me know. I can help you. Thank You.
@anoopkdcs That is correct, thank you. I'll adapt the import.
ModuleNotFoundError: No module named 'keras.engine.topology'
I Got the Same error .
Help Me to solve this problem .
import tflearn import numpy as np from sklearn.manifold import TSNE import matplotlib.pyplot as plt from tflearn.layers.core import input_data, dropout, fully_connected from tflearn.layers.conv import conv_1d, global_max_pool from tflearn.layers.merge_ops import merge from tflearn.layers.estimator import regression import tensorflow as tf import os os.environ['KERAS_BACKEND']='theano' from keras.layers import Embedding from keras.layers import Dense, Input, Flatten from keras.layers import Conv1D, MaxPooling1D, Embedding, concatenate, Dropout, LSTM, GRU, Bidirectional from keras.models import Model,Sequential
from keras import backend as K from keras.engine.topology import Layer, InputSpec from keras.layers import Layer from keras import initializers, optimizers
def lstm_keras(inp_dim, vocab_size, embed_size, num_classes, learn_rate):
model = Sequential()
model.add(Embedding(vocab_size, embed_size, input_length=inp_dim, trainable=True))
model.add(Dropout(0.25))
model.add(LSTM(embed_size))
model.add(Dropout(0.50))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
return model
def cnn(inp_dim, vocab_size, embed_size, num_classes, learn_rate): tf.reset_default_graph() network = input_data(shape=[None, inp_dim], name='input') network = tflearn.embedding(network, input_dim=vocab_size, output_dim=embed_size, name="EmbeddingLayer") network = dropout(network, 0.25) branch1 = conv_1d(network, embed_size, 3, padding='valid', activation='relu', regularizer="L2", name="layer_1") branch2 = conv_1d(network, embed_size, 4, padding='valid', activation='relu', regularizer="L2", name="layer_2") branch3 = conv_1d(network, embed_size, 5, padding='valid', activation='relu', regularizer="L2", name="layer_3") network = concatenate([branch1, branch2, branch3], mode='concat', axis=1) network = tf.expand_dims(network, 2) network = global_max_pool(network) network = dropout(network, 0.50) network = fully_connected(network, num_classes, activation='softmax', name="fc") network = regression(network, optimizer='adam', learning_rate=learn_rate, loss='categorical_crossentropy', name='target')
model = tflearn.DNN(network, tensorboard_verbose=0)
return model
def blstm(inp_dim,vocab_size, embed_size, num_classes, learn_rate):
model = Sequential()
model.add(Embedding(vocab_size, embed_size, input_length=inp_dim, trainable=True))
model.add(Dropout(0.25))
model.add(Bidirectional(LSTM(embed_size)))
model.add(Dropout(0.50))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
return model
class AttLayer(Layer):
def __init__(self, **kwargs):
super(AttLayer, self).__init__(**kwargs)
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.W = self.add_weight(name='kernel',
shape=(input_shape[-1],),
initializer='random_normal',
trainable=True)
super(AttLayer, self).build(input_shape) # Be sure to call this somewhere!
def call(self, x, mask=None):
eij = K.tanh(K.dot(x, self.W))
ai = K.exp(eij)
weights = ai/K.sum(ai, axis=1).dimshuffle(0,'x')
weighted_input = x*weights.dimshuffle(0,1,'x')
return weighted_input.sum(axis=1)
def compute_output_shape(self, input_shape):
return (input_shape[0], input_shape[-1])
def blstm_atten(inp_dim, vocab_size, embed_size, num_classes, learn_rate):
model = Sequential()
model.add(Embedding(vocab_size, embed_size, input_length=inp_dim))
model.add(Dropout(0.25))
model.add(Bidirectional(LSTM(embed_size, return_sequences=True)))
model.add(AttLayer())
model.add(Dropout(0.50))
model.add(Dense(num_classes, activation='softmax'))
adam = optimizers.Adam(lr=learn_rate, beta_1=0.9, beta_2=0.999)
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
return model
def get_model(m_type,inp_dim, vocab_size, embed_size, num_classes, learn_rate): if m_type == 'cnn': model = cnn(inp_dim, vocab_size, embed_size, num_classes, learn_rate) elif m_type == 'lstm': model = lstm_keras(inp_dim, vocab_size, embed_size, num_classes, learn_rate) elif m_type == "blstm": model = blstm(inp_dim) elif m_type == "blstm_attention": model = blstm_atten(inp_dim, vocab_size, embed_size, num_classes, learn_rate) else: print ("ERROR: Please specify a correst model") return None return model
HY starboyvarus how did you solve the this ModuleNotFoundError: No module named 'keras.engine.topology'
@anoopkdcs Thank you for replying. I already solved this issue. If you are using janggu in google collab and facing any issue let me know. I can help you. Thank You.
Hi, how do you solve it with Jupyter Notebook and not Colab. I know it works on Colab but if you've got to use local machine, you know what I mean.
I am getting the same issue can anyone help
I am also getting same error cannot import name 'Network' from 'keras.engine.topology
Which versions of tensorflow, keras and janggu are you using? The issue is likely related to using incompatible library versions. Please use: tensorflow==2.2, keras==2.4.3 and janggu==0.10.2 (or follow the alternative installation instructions on the readme page). Thank you very much
Whenever I am trying to run any src folder file. It gives this error. I have already tried this from stackoverflow: from tensorflow.keras.layers import Layer, InputSpec , and several other things but still it's showing this error. Can please help me solve this. ThankYou.