'Model' object has no attribute 'predict'

Hello,
I have done the code below but i am getting an error.

vs = cv2.VideoCapture(video_path)
output_video_1,output_video_2 = None,None
# Loop until the end of the video stream
while True:	
	# Load the image of the ground and resize it to the correct size
	img = cv2.imread("../img/chemin_1.png")
	bird_view_img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
	
	# Load the frame
	(frame_exists, frame) = vs.read()
	# Test if it has reached the end of the video
	if not frame_exists:
		break
	else:
		# Resize the image to the correct size
		frame = imutils.resize(frame, width=int(size_frame))
		
		# Make the predictions for this frame
		(boxes, scores, classes) =  model.predict(frame)

This is the error:

that’s not the whole code.

where and how is model defined? what type/class is it?

please do your own debugging before you ask others to spend time on your problem.

Sorry. This happened because i am new to python.
Here is defined the model

import numpy as np
import tensorflow as tf
import cv2
import time
class Model:
    """
    Class that contains the model and all its functions
    """
    def __init__(self, model_path):
        """
        Initialization function
        @ model_path : path to the model 
        """

        # Declare detection graph
        self.detection_graph = tf.Graph()
        # Load the model into the tensorflow graph
        with self.detection_graph.as_default():
            od_graph_def = tf.compat.v1.GraphDef()
            with tf.io.gfile.GFile(model_path, 'rb') as file:
                serialized_graph = file.read()
                od_graph_def.ParseFromString(serialized_graph)
                tf.import_graph_def(od_graph_def, name='')

        # Create a session from the detection graph
        self.sess = tf.compat.v1.Session(graph=self.detection_graph)
def predict(self,img):
        """
        Get the predicition results on 1 frame
        @ img : our img vector
        """
        # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
        img_exp = np.expand_dims(img, axis=0)
        # Pass the inputs and outputs to the session to get the results 
        (boxes, scores, classes) = self.sess.run([self.detection_graph.get_tensor_by_name('detection_boxes:0'), self.detection_graph.get_tensor_by_name('detection_scores:0'), self.detection_graph.get_tensor_by_name('detection_classes:0')],feed_dict={self.detection_graph.get_tensor_by_name('image_tensor:0'): img_exp})
        return (boxes, scores, classes)

and then i am imported it in this line
from tf_model_object_detection import Model
but it showes me that error.

predict() is indeed NOT a member function of your Model class —
that’s a silly indentation problem ! (welcome to python …)

you have to add 4 spaces indentation before that, so it is inside the Model class again

hmm i did it but the error is still there :frowning:

if that code is in a cell, you have to re-run that !

if you edit code, that is not in a cell (but a file),
you need to restart the notebook (or runtime).

thank you very much . it is okay now.

seriosly, you want to know your tools, before venturing into this …
(and NONE of it was about opencv !)