0

I ran a CNN model for image analysis, my model and weights saved to kaggle/working, however I spent hours trying to download these using combination of methods, clicking the … adjacnent to the file and selecting 'Download' did not work, no response .

So i shut web browser and laptop down and rebooted and looked back in Notebook editor and the files were no longer there in kaggle/working so i need to run my model again - what I am missing- should these files persist and is there an issue with the 'Download' button? If i am not saving in correct place , where should I save so files persist ? The 'Output' in my notebook interface only holds a log of events recorded at runtime.

I have modified my code to create links and save to local machine just in case I have further issues:

import shutil
import os
from IPython.display import display, HTML

# Specify the save directory on your local machine
save_directory = '/Users/callanmooneys/Downloads/'

# Define the save path in Kaggle
save_path = '/kaggle/working/'

# Define the model name, subject, and accuracy
model_name = model.input_names[0][:-6]
subject = "ALL_Classification"
acc = test_score[1] * 100

# Save model
save_id = f'{model_name}-{subject}-{acc:.2f}.h5'
model_save_loc = os.path.join(save_path, save_id)
model.save(model_save_loc)
print(f"Model was saved as {model_save_loc}")

# Save model copy to local machine
local_model_save_loc = os.path.join(save_directory, save_id)
shutil.copy(model_save_loc, local_model_save_loc)
print(f"Model was also saved as {local_model_save_loc}")

# Generate download link for model
model_download_link = f'<a href="file://{local_model_save_loc}" download="{save_id}">Download Model</a>'
display(HTML(model_download_link))

# Save weights
weight_save_id = f'{model_name}-{subject}-weights.h5'
weights_save_loc = os.path.join(save_path, weight_save_id)
model.save_weights(weights_save_loc)
print(f"Weights were saved as {weights_save_loc}")

# Save weights copy to local machine
local_weights_save_loc = os.path.join(save_directory, weight_save_id)
shutil.copy(weights_save_loc, local_weights_save_loc)
print(f"Weights were also saved as {local_weights_save_loc}")

# Generate download link for weights
weights_download_link = f'<a href="file://{local_weights_save_loc}" download="{weight_save_id}">Download Weights</a>'
display(HTML(weights_download_link))

Thanks In Advanceenter code here

dancingbush
  • 2,131
  • 5
  • 30
  • 66

1 Answers1

0

This feedback may be useful to new Kaggle notebook users like myself;

  1. To allow internet access in Kaggle notebook (it is disabled by default ) , you must enable via the very small / easy to miss 'arrow ' button bottom left hand side of notebook, this reveals a sliding menu with option to enable Internet access.

  2. Saving and downloading models and model weights: The models will not appear in your 'Output' in Notebook interface / overview. You need to save to

'/kaggle/working/'

directory, which is accessible again via sliding menu (see above) These files will not persist by default, you must allow 'File' Persistence via sliding menu (see above), otherwise you may well lose your data like I did.

enter image description here

dancingbush
  • 2,131
  • 5
  • 30
  • 66