Need help please C1_W3_Assignment UNQ_C1

My code generates this error and I don’t know how to fix itMy code generates this error and I don’t know how to fix it

Wrong output

this is my code:


# UNQ_C1 (UNIQUE CELL IDENTIFIER, DO NOT EDIT)
def get_sub_volume(image, label, 
# moderator edit: code removed - not allowed by the Code of Conduct}
2 Likes

Generate this error to run:

2 Tests passed
1 Tests failed


AssertionError Traceback (most recent call last)
in ()
1 ### test cell ex1 - do not modify this test cell
----> 2 get_sub_volume_test(get_sub_volume)

~/work/W3A1/public_tests.py in get_sub_volume_test(target)
68 ]
69
—> 70 learner_func_sample_image, learner_func_sample_label = multiple_test_get_sub_volume(test_cases, target)
71
72 print(“\033[0m\nSampled Image:”)

~/work/W3A1/test_utils.py in multiple_test_get_sub_volume(test_cases, target)
160 print(‘\033[92m’, success," Tests passed")
161 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
→ 162 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
163
164 return learner_func_answer

AssertionError: Not all tests were passed for get_sub_volume. Check your equations and avoid using global variables inside the function.

1 Like

compute the background ratio (this has been implemented for you)

    bgrd_ratio = recall this  code with right Numpy function
  • To check the ratio of background to the whole sub-volume, the numerator is the number of background labels in the sub-volume. The last dimension of the label array at index 0 contains the labels to identify whether the voxel is a background (value of 1) or not a a background (value of 0).
1 Like

I made the modification but the error remains the same

bgrd_ratio = np.sum(y[:,:,:,0])/(output_x * output_y * output_z)

1 Like

Alexander,

According to your error log, you are using global variables inside a function which is creating this error. Kindly go through the grader cell before get_Sub volume and check where you must have done this and do the correction.

In this code while randomly sampling you misplaced or mixed(incorrect code) the output with your sampling. Check the first 3 code lines, you will get what mistake you have done. you needs randomly sample from the same sub volume and don’t mix it y with x or z with x while randomly sampling.

while tries < max_tries:
# randomly sample sub-volume by sampling the corner voxel
# hint: make sure to leave enough room for the output dimensions!
# do not remove/delete the '0’s
start_y = …(…, … - …_x + …)???
start_z = …(…, …-…_x + …)???

If unable to find, then send me the notebook

Regards
DP

2 Likes

You are absolutely right, the error was that it was randomizing the volumes y and z
mixing them with the volume x. I had to mix them with their respective volumes, x with x, y with y and z with z in inputs minus outputs. solved. thank you.

1 Like

Hi! I got the same error, but i did not understand how to solve it. Can you help me? Thank you

1 Like

Hi @Enrico_Randellini,

You may want to have a closer look at the function’s arguments and how you are using each one of those in your code. In addition, you may want to check the hints above the exercise.
Let me know if that helps.

1 Like

Please don’t share codes on public post threads

I Am sorry. I removed the shared code. Anyway, the error persist

1 Like

@Enrico_Randellini,

It is always a better approach to create a new post for any error, query or issue you get and share a screenshot of your error you got. Chances are your error log might be same but the reason could be different, so to have better response, please share screenshot of the error. You can DM the codes. Click on the name of any of the two mentors who have responded you here.

Regards
DP

1 Like

Solved, thanks for the comments!

1 Like

Thanks, Deepti, for this formula. The + really helped me. Without + wasted half a day debugging… :face_with_head_bandage:

1 Like