JuanFMontesinos / Acappella-YNet

Official implementation of A cappella: Audio-visual Singing VoiceSeparation, from BMVC21
https://ipcv.github.io/Acappella/
14 stars 4 forks source link

UnboundLocalError: local variable 'warped_img' referenced before assignment #7

Open yddr opened 2 years ago

yddr commented 2 years ago

Hi, thanks for releasing your code and dataset. I encounter this error on executing preprocess.py


Exception Handled:  'NoneType' object is not iterable
  0%|                                                                                                                                           |
 samples processed:   0%|
Traceback (most recent call last):
  File "preprocess.py", line 314, in <module>
    mean_face)
  File "preprocess.py", line 254, in process_samples
    del warped_img, landmarks, bbox, vid, stacked_frames, stacked_landmarks
UnboundLocalError: local variable 'warped_img' referenced before assignment

Error log is saying that 'warped_img' isn't assigned. So I checked 'warped_img' and that Errorhandling code.

In 231 line, in preprocess_sample function,

with tqdm(total=num_frames) as pbar:
                for num_frame in range(num_frames):
                    try:
                        img_raw = vid.get_data(num_frame)
                    except IndexError as e:
                        print("Processing FAILED for sample: " + sample_id)
                        break
                    if img_raw.shape[1] >= MAX_IMAGE_WIDTH:
                        asp_ratio = img_raw.shape[0] / img_raw.shape[1]
                        dim = (MAX_IMAGE_WIDTH, int(MAX_IMAGE_WIDTH * asp_ratio))
                        new_img = cv2.resize(img_raw, dim, interpolation=cv2.INTER_AREA)
                        img = np.asarray(new_img)
                    else:
                        img = img_raw
                    try:
                        **_warped_img, landmarks, bbox = fp.process_image(img)_**
                        _, aligned_landmarks, _ = fp.process_image(warped_img)
                        good_frame_ids.append(num_frame)
                    except Exception as e:
                        print("Exception Handled: ", e)
                        continue

I think face detector can't find face , but I don't know why If you give advice to me, I'm very appreciate.

JuanFMontesinos commented 2 years ago

Seems an strange error if we evaluate the code:

            with tqdm(total=num_frames) as pbar:
                for num_frame in range(num_frames):
                    try:
                        img_raw = vid.get_data(num_frame)
                    except IndexError as e:
                        print("Processing FAILED for sample: " + sample_id)
                        break
                    if img_raw.shape[1] >= MAX_IMAGE_WIDTH:
                        asp_ratio = img_raw.shape[0] / img_raw.shape[1]
                        dim = (MAX_IMAGE_WIDTH, int(MAX_IMAGE_WIDTH * asp_ratio))
                        new_img = cv2.resize(img_raw, dim, interpolation=cv2.INTER_AREA)
                        img = np.asarray(new_img)
                    else:
                        img = img_raw
                    try:
                        warped_img, landmarks, bbox = fp.process_image(img)
                        _, aligned_landmarks, _ = fp.process_image(warped_img)
                        good_frame_ids.append(num_frame)
                    except Exception as e:
                        print("Exception Handled: ", e)
                        continue

                    if warped_img is None:
                        print("NONE TYPE RETURNED")
                        continue

                    img_frame = warped_img[:crop_height, :crop_width, :]
                    llcp_input_frame = cv2.resize(img_frame, (160, 160))
                    stacked_llcp_input_frames[num_frame] = llcp_input_frame
                    img_frame_resized = cv2.resize(img_frame, (96, 128))
                    stacked_frames[num_frame] = img_frame_resized
                    aligned_landmarks_resized = aligned_landmarks * [96 / crop_width, 128 / crop_height]
                    stacked_landmarks[num_frame] = aligned_landmarks_resized
                    pbar.update(1)

                np.save(os.path.join(frames_path, sample_id), stacked_frames)
                np.save(os.path.join(landmarks_path, sample_id), stacked_landmarks)
                del warped_img, landmarks, bbox, vid, stacked_frames, stacked_landmarks

The most plausible case seems to be the streamer is not detecting frames in your video file/object This would go to the break that skips the definition of warped_img and throw that error.

The reader relies on vid = imageio.get_reader(sample_file_path, 'ffmpeg') imageio, which is a very stable library. Mi conclusion is your filepath is wrong, the video format is not compatible or the stream corresponding to the video is empty.

yddr commented 2 years ago

Thanks for replying. Well, I think so too... So I saved that image and checked the 'img'. warped_img, landmarks, bbox = fp.process_image(img)

That image is 'b7CByL7u-k' in test_unseen split.

check

I don't think there's anything wrong with this image. Lastly, please give me some advice. Thank you.