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

About Saving Unet The Results in .h5 format #115

Closed
fharman opened this issue Nov 26, 2020 · 14 comments
Closed

About Saving Unet The Results in .h5 format #115

fharman opened this issue Nov 26, 2020 · 14 comments

Comments

@fharman
Copy link

fharman commented Nov 26, 2020

Hi,

I saved the model for Fastmri Public Leaderboard but always encountered an error as EvalException: file1001066_v2.h5 does not exist in your submission. It is available in that folder. How did you save and upload your model results that i really want to know?

Thank you for all your support,

Best Regards,

@zaccharieramzi
Copy link
Owner

Hi @fharman ,

I did not provide a script to perform the inference using the functional models (the old ones).

Can you show me the code you used so that I can help you debug it?

I just tested to see whether the sequences in 'testing' mode indeed contained the expected number of test files, and it's the case, see:

from fastmri_recon.data.sequences.fastmri_sequences import ZeroFilled2DSequence
test_path = ...  # your test path here
seq_4 = ZeroFilled2DSequence(
    test_path,
    mode='testing',
    af=4,
    contrast=None,
    norm=True,
)
seq_8 = ZeroFilled2DSequence(
    test_path,
    mode='testing',
    af=8,
    contrast=None,
    norm=True,
)
print(len(seq_4.filenames), len(seq_8.filenames))

Which returns 50, 58, and there are 108 files for the test set.

@zaccharieramzi
Copy link
Owner

In the colab you linked, I didn't see where you performed the inference to predict the test images.

Also please note that since #113 you no longer need to switch to an older commit for correct results using the U-net, I corrected the error.

@zaccharieramzi
Copy link
Owner

Ok I see now, let me see.

@zaccharieramzi
Copy link
Owner

So your function save_figure (consider changing the name for greater readability) is the one that I guess you wanted to use to save your results (I am rewriting it here for clarity).

def save_figure(im_recos, name):
    global img_index
    with h5py.File(test_gen_scaled.filenames[img_index],'r') as f:
    
        for slice_index in range(f.get('kspace').shape[0]):
            im_reco = im_recos[ slice_index ]
            image_name=test_gen_scaled.filenames[img_index][78:len(test_gen_scaled.filenames[img_index])-6]
            # im_gt = img_batch[slice_index]
            # im_res = np.abs(im_gt - im_reco)
            fig, ax = plt.subplots ( 1, frameon=False )
            ax.imshow ( np.abs ( np.squeeze ( im_reco ) ), aspect='auto' )
            ax.axis ( 'off' )
            fig.savefig (f'/content/drive/My Drive/fastmri-reproducible-benchmark-bcd3fddb48ad324566a44b23c4439ff7a50a316e/TestFigures2/AF8/{image_name}_{slice_index}_{name}_recon_af{AF}.png' )
            
            # fig, ax = plt.subplots(1, frameon=False)
            # ax.imshow(np.abs(np.squeeze(im_res)), aspect='auto')
            # ax.axis('off')
            # fig.savefig(f'/content/drive/My Drive/UNET_Colab/fastmri_reproducible_benchmark_master/TestFigures/trivial_{name}_residu_af{AF}.png')
    
    img_index += 1

However, you didn't open the correct file, you opened the original test file rather than a newly created output file with the correct naming (see the guidelines here).
Also, in this function, you never write to that file but instead save a matplotlib figure, you should save to the newly created h5 file instead.

Also, I think in Python it's recommended to not use global variables in the general case, you should try rewriting this function also without a global variable.

@fharman
Copy link
Author

fharman commented Nov 26, 2020 via email

@zaccharieramzi
Copy link
Owner

@fharman I did not do any correction in the function, I just rewrote it in the issue for logging's sake.

The folders you are showing me are full of png images. For this challenge you need to submit h5 files: please read the guidelines on how to submit.

Alternatively, you can also take inspiration from this function or the one of the official repo.

@fharman
Copy link
Author

fharman commented Nov 26, 2020 via email

@fharman
Copy link
Author

fharman commented Nov 26, 2020 via email

@fharman
Copy link
Author

fharman commented Nov 27, 2020

Hi,

Sorry for my faults and misunderstanding. But I try to learn and revise myself according to your reply. I want to ask you about fastmri-reproducible-benchmark/fastmri_recon/evaluate/utils/write_results.py /

write_result(exp_id, result, filename, coiltype='multicoil', scale_factor=1e6, brain=False, challenge=False) in this line, what is exp_id?

Thank you for your patience and reply,

Best,

@zaccharieramzi
Copy link
Owner

I added a Pull Request (PR) where I specify the docs of this function. Please take a look.

@fharman
Copy link
Author

fharman commented Nov 27, 2020 via email

@zaccharieramzi
Copy link
Owner

@fharman it's because the exp_id should be a string. Here you just put Unet without specifying that it was a string.

@zaccharieramzi
Copy link
Owner

Hi @fharman ,

Can we close this?

@fharman
Copy link
Author

fharman commented Dec 19, 2020 via email

@fharman fharman closed this as completed Dec 19, 2020
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