1
$\begingroup$

I have created a config file with the following code for an object detection task and saved in the local disk.

# Create the config
C = Config()
C.use_horizontal_flips = horizontal_flips
C.use_vertical_flips = vertical_flips
C.rot_90 = rot_90
C.record_path = record_path
C.model_path = output_weight_path
C.num_rois = num_rois
C.base_net_weights = base_weight_path

with open(config_output_filename, 'wb') as config_f:
pickle.dump(C,config_f)

I am trying to load this pickle file in another jupyter notebook.

with open(config_output_filename, "rb") as f:
C = pickle.load(f)    
# turn off any data augmentation at test time
C.use_horizontal_flips = False
C.use_vertical_flips = False
C.rot_90 = False
print(C.num_rois)

But it gives me the following error.

------------------------------------------------------------------------ 

AttributeError             Traceback (most recent call 
last)
 <ipython-input-20-c5528d5ef98b> in <module>
  1 with open(config_output_filename, "rb") as f:
   ----> 2     C = pickle.load(f)

  AttributeError: Can't get attribute 'Config' on <module '__main__'>

But I was able to load the pickle file from the disk without errors in my previous attempts and applied the configurations on the test set.

$\endgroup$
1
$\begingroup$

I guess the Config() is a class that you created. It will be needed again when you load a pickle file storing the config. Therefore, you need to import it in the jupyter notebook you use to load your pickle file.

Hope this could be helpful.

| improve this answer | |
$\endgroup$
1
$\begingroup$

One option is to refactor the code to use a Python dictionary. A Python dictionary can be serialized as pickle or json.

config = {"use_horizontal_flips": True,
          "use_vertical_flips":   False,
        }
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.