Train model ResNet don't work Predict threading code in Python

I release prediction image used(ResNet) from folder(.jpg).
from imageai.Prediction import ImagePrediction
import os
import threading
import time
start_time = time.time()

execution_path = os.getcwd()
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, “resnet50_weights_tf_dim_ordering_tf_kernels.h5”))

prediction.loadModel()

pictures_folder = os.path.join(execution_path, ‘C:/work/rec/unlabeled2017/’)
all_files = os.listdir(pictures_folder)

class PredictionThread(threading.Thread):
def init(self):
threading.Thread.init(self)
def run(self):
global prediction
prediction_thread = prediction
prediction_thread.loadModel()
count = 0
for eachPicture in all_files:
if (eachPicture.endswith(’.png’)
or eachPicture.endswith(’.jpg’)):
predictions, probabilities = prediction_thread.predictImage(os.path.join(pictures_folder, eachPicture), result_count=5)

            for prediction, probability in zip(predictions, probabilities):
                print(prediction, " : ", probability, "%")
            print("_______________________________")
            count += 1
            print("--- %s seconds ---" % (time.time() - start_time), " nubmer pic: ", count)

predictionThread = PredictionThread()
predictionThread.run ()
This my code.
This line–>>>>
prediction.setModelPath(os.path.join(execution_path, “resnet50_weights_tf_dim_ordering_tf_kernels.h5”))

I used my .h5 ModelTraininig

from imageai.Prediction import ImagePrediction
import os
import threading
import time
start_time = time.time()

execution_path = os.getcwd()
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, “model_ex-007_acc-0.877273.h5”))

prediction.loadModel()

pictures_folder = os.path.join(execution_path, ‘C:/work/rec/unlabeled2017/’)
all_files = os.listdir(pictures_folder)

class PredictionThread(threading.Thread):
def init(self):
threading.Thread.init(self)
def run(self):
global prediction
prediction_thread = prediction
prediction_thread.loadModel()
count = 0
for eachPicture in all_files:
if (eachPicture.endswith(’.png’)
or eachPicture.endswith(’.jpg’)):
predictions, probabilities = prediction_thread.predictImage(os.path.join(pictures_folder, eachPicture), result_count=5)

            for prediction, probability in zip(predictions, probabilities):
                print(prediction, " : ", probability, "%")
            print("_______________________________")
            count += 1
            print("--- %s seconds ---" % (time.time() - start_time), " nubmer pic: ", count)

predictionThread = PredictionThread()
predictionThread.run ()

I see ERROR
Call initializer instance with the dtype argument instead of passing it to the constructor
Traceback (most recent call last):
File “C:\Users\User\Anaconda3\lib\site-packages\imageai\Prediction_init_.py”, line 125, in loadModel
model = ResNet50(model_path=self.modelPath, model_input=image_input)
File “C:\Users\User\Anaconda3\lib\site-packages\imageai\Prediction\ResNet\resnet50.py”, line 115, in ResNet50
model.load_weights(weights_path)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py”, line 162, in load_weights
return super(Model, self).load_weights(filepath, by_name)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\network.py”, line 1424, in load_weights
saving.load_weights_from_hdf5_group(f, self.layers)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py”, line 759, in load_weights_from_hdf5_group
K.batch_set_value(weight_value_tuples)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\keras\backend.py”, line 3066, in batch_set_value
assign_op = x.assign(assign_placeholder)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py”, line 1141, in assign
self._shape.assert_is_compatible_with(value_tensor.shape)
File “C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py”, line 1103, in assert_is_compatible_with
raise ValueError(“Shapes %s and %s are incompatible” % (self, other))
ValueError: Shapes (2048, 1000) and (2048, 9) are incompatible

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:/Users/User/PycharmProjects/CudaforPy/imgNew.py”, line 12, in
prediction.loadModel()
File “C:\Users\User\Anaconda3\lib\site-packages\imageai\Prediction_init_.py”, line 129, in loadModel
raise ValueError(“You have specified an incorrect path to the ResNet model file.”)
ValueError: You have specified an incorrect path to the ResNet model file.

I use next code for Train My Model(ResNet.h5)

from imageai.Prediction.Custom import ModelTrainig
import os
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory(“D:”)
model_trainer.trainModel(num_objects=9, num_experiments=50, enhance_data=True, batch_size=32, show_network_summary=True,transfer_from_model=“C:/Users/untitled7/resnet50_weights_tf_dim_ordering_tf_kernels.h5”, initial_num_objects=10)

Please help, solve the problem.

@vraizen Kindly set the parameter thread_safe=True in your predictImage() function.