Reputation: 11
So, I am doing a linkedin learning course on the basic of keras and tensorflow as I am very interested in learning these technologies. However, setting up tensorflow has been probably one of the most painful things Ive ever had to do.
I am running a Conda Enviornment with python 3.7 on mac OS just for perspective.
When attempting to run the following code;
import pandas as pd
from keras.models import Sequential
from keras.layers import *
training_data_df = pd.read_csv("sales_data_training_scaled.csv")
X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values
# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(50, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(loss="mean_squared_error", optimizer="adam")
I get the following error message.
ModuleNotFoundError: No module named 'tensorflow.contrib'
Ive tried a bunch of different things like importing tensorflow.compat.v1 and disabling v2 but that only seems to break things worse. I am stuck, if anyone could help it would be much appreciated.
I am using tensorflow 2.0.0 and keras 2.0.6
after switching my import statements to
import pandas as pd
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
I no longer receive the ModuleNotFound error however I am receiving this:
Python 3.7.7 (default, May 6 2020, 04:59:01) [Clang 4.0.1 (tags/RELEASE_401/final)] on darwin runfile('/Users/shaneschipper/Desktop/Code/Machine Learning Projects/Ex_Files_Building_Deep_Learning_Apps/Exercise Files/03/create_model final.py', wdir='/Users/shaneschipper/Desktop/Code/Machine Learning Projects/Ex_Files_Building_Deep_Learning_Apps/Exercise Files/03') 2020-07-14 09:52:37.558165: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags. 2020-07-14 09:52:37.558405: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance.
I am not really sure what this means, it may be just a warning flag and be working properly but I don't know.
Upvotes: 0
Views: 102
Reputation: 996
As mentioned in M Z's comment, the tensorflow and keras modules you have installed may not be compatible. To avoid this, I always use the version of keras found within the tensorflow module. Try changing your imports to the following:
import pandas as pd
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
If that doesn't solve your issue, posting the version of tensorflow and keras that you have installed will help others aid you with further troubleshooting.
EDIT: After making that change, it is a good sign that you are no longer getting the error. I don't know for sure the meaning of the message you are getting now, but tensorflow tends to give some information when it is first imported depending on the architecture you are using.
The code you have posted only defines and complies the model. Your next steps should probably be to fit the model to your training data. Then you can test the model on a test data set and see if the results are what you would expect.
Upvotes: 1