簡體   English   中英

在Flask服務器上加載pickle文件時如何修復AttributeError?

[英]How to fix AttributeError when loading pickle file on flask server?

我正在嘗試在我的燒瓶服務器上加載一個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 -

泡菜文件是我在名為config.py文件中定義的Config對象:

這是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

我正在嘗試從routes.py文件加載配置文件,但是我總是會遇到該屬性錯誤。

這是我已經嘗試過的一些方法:

  • from config import Config routes.py文件中的from config import Config
  • 在route.py文件中定義了class Config本身

看起來它只是在'/Users/sleepyotter/anaconda3/envs/project/bin/flask'尋找Config類...為什么找不到我導入到route.py文件中的Config類?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM