ModuleNotFoundError: No module named 'tensorflow.python.platform'

213 Views Asked by At

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
0

There are 0 best solutions below