创建一个API以公开使用fast.ai CNN创建的dl模型

时间:2018-07-19 18:28:36

标签: python flask artificial-intelligence conv-neural-network

我正在使用fast.ai进行图像分类。我已经创建了dl模型。现在,我想将模型公开为一个api。我正在使用以下存储库https://github.com/alexcnwy/flask_fastai_CNN 公开dl模型。它需要模型权重。

我使用fastai / courses / dl1 / lesson1.ipynb,并保存以下权重:

arch=resnet34
data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
learn.save('modelweights')

但是在我运行python server.py时将模型权重(modelweights.h5)保存到flask_fastai_CNN / static / _model后, 它引发以下错误

### start server  2018-07-19 12:01:39.808413

### image upload folder: /home/ubuntu/flask_fastai_CNN/static/_uploads/unknown/

### data folder: /home/ubuntu/flask_fastai_CNN/static/data/redux
Using gpu device 0: Tesla K80 (CNMeM is disabled, cuDNN Mixed dnn version. The header is from one version, but we link with a different version (5103, 7005))
Using Theano backend.

### initializing model: 
VVV/home/ubuntu/flask_fastai_CNN/static/_model/modelweights.h5
Traceback (most recent call last):
  File "server.py", line 52, in <module>
    vgg = Vgg16()
  File "/home/ubuntu/flask_fastai_CNN/utils/vgg16.py", line 32, in __init__
    self.create()
  File "/home/ubuntu/flask_fastai_CNN/utils/vgg16.py", line 84, in create
    model.load_weights(trained_model_path)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 2494, in load_weights
    f = h5py.File(filepath, mode='r')
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/h5py/_hl/files.py", line 269, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/h5py/_hl/files.py", line 99, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 78, in h5py.h5f.open
IOError: Unable to open file (file signature not found) 

我已将fast.ai部署在AWS ubuntu p2.xlarge实例中。我还使用了h5debug和h5dump命令来访问文件,但是两者均导致cannot open file。请任何人都可以告诉我我错了。预先感谢!

0 个答案:

没有答案