[英]How to fix AttributeError when loading pickle file on flask server?
I'm trying to load a pickle file model_vgg_config2.pickle
on my flask server, but I keep running into the following error: 我正在尝试在我的烧瓶服务器上加载一个pickle文件model_vgg_config2.pickle
,但是我一直model_vgg_config2.pickle
以下错误:
Traceback (most recent call last):
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/sleepyotter/anaconda3/envs/project/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/sleepyotter/Desktop/Product_Analytics/project/code/app/routes_2.py", line 66, in index
detector.load_model(detector_weights, detector_config)
File "/Users/sleepyotter/Desktop/Product_Analytics/project/code/app/models/frcnn_detector/frcnn.py", line 89, in load_model
config = pickle.load(f_in)
AttributeError: Can't get attribute 'Config' on <module '__main__' from '/Users/sleepyotter/anaconda3/envs/project/bin/flask'>
127.0.0.1 - - [27/Apr/2019 11:25:56] "POST / HTTP/1.1" 500 -
The pickle file is a Config
object which I have defined in a file called config.py
file: 泡菜文件是我在名为config.py
文件中定义的Config
对象:
Here is config.py : 这是config.py :
class Config:
def __init__(self):
# Print the process or not
self.verbose = True
# Name of base network
self.network = 'vgg'
# Setting for data augmentation
self.use_horizontal_flips = False
self.use_vertical_flips = False
self.rot_90 = False
# Anchor box scales
# Note that if im_size is smaller, anchor_box_scales should be scaled
# Original anchor_box_scales in the paper is [128, 256, 512]
self.anchor_box_scales = [64, 128, 256]
# Anchor box ratios
self.anchor_box_ratios = [[1, 1], [1./math.sqrt(2), 2./math.sqrt(2)], [2./math.sqrt(2), 1./math.sqrt(2)]]
# Size to resize the smallest side of the image
# Original setting in paper is 600. Set to 300 in here to save training time
self.im_size = 300
# image channel-wise mean to subtract
self.img_channel_mean = [103.939, 116.779, 123.68]
self.img_scaling_factor = 1.0
# number of ROIs at once
self.num_rois = 4
# stride at the RPN (this depends on the network configuration)
self.rpn_stride = 16
self.balanced_classes = False
# scaling the stdev
self.std_scaling = 4.0
self.classifier_regr_std = [8.0, 8.0, 4.0, 4.0]
# overlaps for RPN
self.rpn_min_overlap = 0.3
self.rpn_max_overlap = 0.7
# overlaps for classifier ROIs
self.classifier_min_overlap = 0.1
self.classifier_max_overlap = 0.5
# placeholder for the class mapping, automatically generated by the parser
self.class_mapping = None
self.model_path = None
I'm trying to load the config file from the routes.py
file, but I always get that attribute error. 我正在尝试从routes.py
文件加载配置文件,但是我总是会遇到该属性错误。
Here are some things I've already tried: 这是我已经尝试过的一些方法:
from config import Config
within the routes.py
file from config import Config
routes.py
文件中的from config import Config
class Config
itself in the routes.py file 在route.py文件中定义了class Config
本身 It looks like it's only looking for the Config class in '/Users/sleepyotter/anaconda3/envs/project/bin/flask'
... why isn't it finding the Config class that I've imported into the routes.py file? 看起来它只是在'/Users/sleepyotter/anaconda3/envs/project/bin/flask'
寻找Config类...为什么找不到我导入到route.py文件中的Config类?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.