Doodleverse / segmentation_zoo

A collection of geoscientific image segmentation models
MIT License
7 stars 3 forks source link

Issue with dynamic variable loading? #36

Closed WHBSpeiser closed 8 months ago

WHBSpeiser commented 8 months ago

Hey, trying to use the SDSmodels notebook. When I get to the "RGB / 2-class" cells, specifically the third cell where you define M C and T, the cell starting with:

# For each set of weights in W load them in
M= []; C=[]; T = []
for counter,weights in enumerate(W):

I get the error:

Number of samples: 759
Using CPU
Using single CPU device
[]
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]
.....................................
Creating and compiling model 0...
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[54], line 134
    131 print('.....................................')
    132 print('Creating and compiling model {}...'.format(counter))
--> 134 if MODEL =='resunet':
    135     model =  custom_resunet((TARGET_SIZE[0], TARGET_SIZE[1], N_DATA_BANDS),
    136                     FILTERS,
    137                     nclasses=NCLASSES, #[NCLASSES+1 if NCLASSES==1 else NCLASSES][0],
   (...)
    143                     use_dropout_on_upsampling=USE_DROPOUT_ON_UPSAMPLING,
    144                     )
    145 elif MODEL=='unet':

NameError: name 'MODEL' is not defined

I suspect this would be because the MODEL variable is not being defined in the line

for k in config.keys():
        exec(k+'=config["'+k+'"]')

Maybe there was a change in how the weights file were structured after the notebook was published? If I print out config.keys() for the first RGB weights file in the notebook the dictionary keys I get are
dict_keys(['key', 'storage_class', 'checksum', 'size', 'created', 'updated', 'status', 'metadata', 'mimetype', 'version_id', 'file_id', 'bucket_id', 'links'])

But I could be wrong... thank you for any help!

dbuscombe-usgs commented 8 months ago

Hi Will, I'll try to take a look at this early next week (I have a number of doodleverse maintenance tasks).

If 'MODEL' is specified in the config, then it will be parsed as a variable with this code block

for k in config.keys():
        exec(k+'=config["'+k+'"]')

which reads all config lines and assigns them to in-memory variables

WHBSpeiser commented 8 months ago

Thanks Dan! Yeah, for some reason MODEL doesn't seem to be specified in the configs.

WHBSpeiser commented 8 months ago

Hi @dbuscombe-usgs, Re-downloaded the models and the weights again and the problem fixed itself... odd! Thanks for the response nonetheless.