简体   繁体   English

在Flask服务器上加载pickle文件时如何修复AttributeError?

[英]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
  • defined the 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.

相关问题 读取pickle文件时出现属性错误 - AttributeError when reading a pickle file 加载数据库页面(Flask / Heroku)时如何解决内部服务器错误? - How to fix internal server error when loading my database page (Flask/Heroku)? 运行flask服务器时如何修复flask.cli.NoAppException - How to fix flask.cli.NoAppException when running flask server 加载pickle文件时出现python错误消息 - python error message when loading pickle file 当 Flask 服务器正在保存图像文件时,如何解决出现“权限被拒绝”的问题 - How do I fix problem with getting "permission denied" when Flask server is saving an image file 如何修复'ValueError:当allow_pickle = False时无法加载包含腌制数据的文件;? - How to fix ' ValueError: Cannot load file containing pickled data when allow_pickle=False ;? 如何修复 AttributeError: 'int' object has no attribute 'strip' while loading excel file in pandas - How to fix AttributeError: 'int' object has no attribute 'strip' while loading excel file in pandas 如何在加载模型时使用Tensorflow / Keras修复python中的&#39;AttributeError:&#39;list&#39;对象没有属性&#39;shape&#39;错误 - How to fix 'AttributeError: 'list' object has no attribute 'shape'' error in python with Tensorflow / Keras when loading Model 没有文件上传时如何解决Flask中的UploadNotAllowed错误? - How to fix UploadNotAllowed error in Flask when no file is uploaded? 加载npy数组时,无法将文件%s解释为pickle - Failed to interpret file %s as a pickle when loading an npy array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM