Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with siamese_track( ) #213

Open
MsAnitaAli opened this issue Apr 24, 2024 · 1 comment
Open

Issue with siamese_track( ) #213

MsAnitaAli opened this issue Apr 24, 2024 · 1 comment

Comments

@MsAnitaAli
Copy link

MsAnitaAli commented Apr 24, 2024

whenever I clone and use this repo in my notebook. It generates error with this line

state = siamese_track(state, frame, mask_enable=True, refine_enable=True, device=device)

error message is:
AttributeError: module 'numpy' has no attribute 'float'.
np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Apparently it seems, I am using newer version of numpy and use of np.float has been deprecated. I have tried out these.

  1. I have tried to rerun (on my local machine) with older version of numpy from my activated virtual env, but no use.
  2. In Google colab, i have tried to forcefully pip install older version of numpy, it didn't work too.
  3. I tried to replace all occurrences of np.float with float, but didn't work.
  4. i tried to replace all occurrences of np.float64, but it didn't work too.
    Now what to do?

Secondly, in some codes( as in this code), apparently there is no np.float present in our code. It might be possible that definition of siamese_track is using it, but how to locate that definition in entire repo? or should I search for it in all possible .py and .ipnb files that are present in this repo, but how is that possible

My code cell is given below.
steps:
1: Mount drive - running
2: Setting up imports, Clone and Install Darknet (Yolov4) and SiamMask, copying weights - running

3: Detect the object using Yolov4 and track it using SiamMask; -- generating error

def YoloSiam():
f = 0
video_capture = cv2.VideoCapture()
if video_capture.open('target.mp4'):
width, height = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = video_capture.get(cv2.CAP_PROP_FPS)

!rm -f output.mp4 output.avi
# can't write out mp4, so try to write into an AVI file
video_writer = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*'MJPG'), fps, (width, height))

while video_capture.isOpened():
  ret, frame = video_capture.read()
  if not ret:
    break

  if f == 0:

    # detect the object using Yolov4

    #moving into darknet directory
    os.chdir('/content/darknet')

    #saving file name to a txt file
    im='first_frame.jpg'
    with open('image.txt', 'w') as txt_file:
      cv2.imwrite(im,frame)
      txt_file.write(im)
      im = cv2.imread(im)

    #Running  Yolov4 and creating json file
    !./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < image.txt

    # Reading json file
    json_file = open("result.json")
    data = json.load(json_file)
    json_file.close()

    #Extracting relative coordinates from the json file
    relative_coordinates=data[0]['objects'][0]['relative_coordinates']
    rel_center_x=relative_coordinates['center_x']
    rel_center_y=relative_coordinates['center_y']
    rel_width=relative_coordinates['width']
    rel_height=relative_coordinates['height']

    #finding width and height of the image
    img_height, img_width, c= im.shape

    #Calculating absolute coordinates
    w=math.ceil(rel_width*img_width)
    h=math.ceil(rel_height*img_height)
    x=math.ceil(rel_center_x*img_width-w/2) #top left
    y=math.ceil(rel_center_y*img_height-h/2) #top left

    #moving back to root directory
    os.chdir('/content')


    # init SiamMask tracker
    target_pos, target_sz = None, None
    target_pos = np.array([x + w / 2, y + h / 2])
    target_sz = np.array([w, h])
    state = siamese_init(frame, target_pos, target_sz, siammask, cfg['hp'], device=device)
  else:
    # track
    state = siamese_track(state, frame, mask_enable=True, refine_enable=True, device=device)
    location = state['ploygon'].flatten()
    mask = state['mask'] > state['p'].seg_thr

    frame[:, :, 2] = (mask > 0) * 255 + (mask == 0) * frame[:, :, 2]
    cv2.polylines(frame, [np.int0(location).reshape((-1, 1, 2))], True, (0, 255, 0), 3)

    video_writer.write(frame)

  f += 1
  # only on first 200 frames
  if f > 200:
    break

video_capture.release()
video_writer.release()

# convert AVI to MP4
!ffmpeg -y -loglevel info -i output.avi output.mp4

else:
print("can't open the given input video file!")

YoloSiamTime = %timeit -o -n 1 YoloSiam()

Complete Error Message :

AttributeError Traceback (most recent call last)
in <cell line: 88>()
86 print("can't open the given input video file!")
87
---> 88 YoloSiamTime = get_ipython().run_line_magic('timeit', '-o -n 1 YoloSiam()')
89
90 #show video using the helping function defined in #2

8 frames
in timeit(self, line, cell, local_ns)

in inner(_it, _timer)

/usr/local/lib/python3.10/dist-packages/numpy/init.py in getattr(attr)
317
318 if attr in former_attrs:
--> 319 raise AttributeError(former_attrs[attr])
320
321 if attr == 'testing':

AttributeError: module 'numpy' has no attribute 'float'.
np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

@RohitKumar2009
Copy link

I am also facing the same issue. Has anyone got any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants