0

I'm using imageAI with tensorflow and keras. Now I get the problem is : ModuleNotFoundError: No module named 'tensorflow.python.platform'

enter image description here

I have find many different methods to solve it, but they do not work for me. Hope there is someone can help me to solve this problem, thank you here are my code:

imagea.py

import os
import threading
from imageai.Prediction import ImagePrediction
from imageai.Prediction.Custom import ModelTraining
from imageai.Prediction.Custom import CustomImagePrediction

def modelTrain(dataDir='data',classNum=2,epochs=100,batch_size=32):
  model_trainer = ModelTraining()
  model_trainer.setModelTypeAsResNet()
  model_trainer.setDataDirectory(dataDir)

model_trainer.trainModel(num_objects=classNum, num_experiments=epochs,enhance_data=True, batch_size=batch_size, show_network_summary=True)
print('Model Train Finished!!!')



def modelPredict(model_path='data/models/model_ex-001_acc-0.500000.h5',
  class_path='data/json/model_class.json',
  pic_path='a.jpg',classNum=2,resNum=5):

  prediction=CustomImagePrediction()
  prediction.setModelTypeAsResNet()
  prediction.setModelPath(model_path)
  prediction.setJsonPath(class_path)
  prediction.loadModel(num_objects=classNum,prediction_speed='fastest') 
  predictions,probabilities=prediction.predictImage(pic_path,result_count=resNum)
  for eachPrediction, eachProbability in zip(predictions, probabilities):
     print(eachPrediction+" : "+str(eachProbability))

 if __name__=='__main__':
   modelTrain(dataDir='data',classNum=2,epochs=10,batch_size=8)

 modelPredict(model_path='data/models/model_ex-001_acc-0.500000.h5',
 class_path='data/json/model_class.json',
 pic_path='test.jpg',classNum=2,resNum=5)

sidecar_evaluator.py (part of problem)

import tensorflow as tf
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util import deprecation  # pylint: disable=g-direct-tensorflow-import
from tensorflow.python.util.tf_export import keras_export  # pylint: disable=g-direct-tensorflow-import
David
  • 5,882
  • 3
  • 33
  • 44
yannn31
  • 11
  • 4
  • This looks like an internal error in the Tensorflow library (since `sidecar_evaluator.py` appears to be part of Keras). You should raise it on their issue tracker. If you wanna investigate more, you can check out the third section of this answer of mine: https://stackoverflow.com/a/72910378/4691830 – Joooeey Jul 11 '22 at 12:11
  • @Joooeey thanks for your reply! How can I raise it on their issue tracker? I have read your third section of link answer, I get in /site-packages/tensorflow/keras/engine, but I do not know to check which one source code, please help me again, thank you so much!!! https://i.imgur.com/qF5QQSt.png – yannn31 Jul 11 '22 at 12:37
  • This is the relevant issue tracker: https://github.com/tensorflow/tensorflow/issues – Joooeey Jul 11 '22 at 12:38
  • You'd have to search further outside, in `/site-packages/tensorflow`. However, trying to understand that source code may take a lot of time. – Joooeey Jul 11 '22 at 12:39
  • What's the output if you enter `tf.__version__` (after `import tensorflow as tf`) in Python? – Joooeey Jul 11 '22 at 12:40
  • Maybe the location of `tf_logging.py` just moved or the name of the file was changed. – Joooeey Jul 11 '22 at 12:45
  • @Joooeey my tensorflow version is 2.9.1 – yannn31 Jul 12 '22 at 02:12
  • @Joooeey I have copied 「tf_logging.py」 to 「 /site-packages/tensorflow/python/platform」, and it seems works now but now the new one problem come out : No module named 'tensorflow.compat', how can I solve it? – yannn31 Jul 12 '22 at 02:27
  • That `tf_logging.py` wasn't already there is strange and points to a serious problem in your installation or a misunderstanding between the two of us. According to Github, `tf_logging.py` should have been at `.../tensorflow/python/platform/tf_logging.py` since Tensorflow 0.9 came out in 2016. – Joooeey Jul 12 '22 at 10:38

0 Answers0