text: # Licensed to the Apache Software Foundation (ASF) under one
  # or more contributor license agreements.  See the NOTICE file
  # distributed with this work for additional information
  # regarding copyright ownership.  The ASF licenses this file
  # to you under the Apache License, Version 2.0 (the
  # "License"); you may not use this file except in compliance
  # with the License.  You may obtain a copy of the License at
  #
  #   http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing,
  # software distributed under the License is distributed on an
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  # KIND, either express or implied.  See the License for the
  # specific language governing permissions and limitations
  # under the License.
  
  # Modified from https://github.com/dmlc/mxnet/blob/master/example/image-classification/common/modelzoo.py
  
  import os
  from common.util import download_file
  
  _base_model_url = 'http://data.mxnet.io/models/'
  _dummy_model_url = 'http://example.com/'
  _default_model_info = {
      'imagenet1k-caffenet': {'symbol':_base_model_url+'imagenet/caffenet/caffenet-symbol.json',
                              'params':_base_model_url+'imagenet/caffenet/caffenet-0000.params'},
      'imagenet1k-squeezenet': {'symbol':_base_model_url+'imagenet/squeezenet/squeezenet_v1.1-symbol.json',
                                'params':_base_model_url+'imagenet/squeezenet/squeezenet_v1.1-0000.params'},
      'imagenet1k-nin': {'symbol':_base_model_url+'imagenet/nin/nin-symbol.json',
                         'params':_base_model_url+'imagenet/nin/nin-0000.params'},
      'imagenet1k-vgg16': {'symbol':_base_model_url+'imagenet/vgg/vgg16-symbol.json',
                           'params':_base_model_url+'imagenet/vgg/vgg16-0000.params'},
      'imagenet1k-vgg19': {'symbol':_base_model_url+'imagenet/vgg/vgg19-symbol.json',
                           'params':_base_model_url+'imagenet/vgg/vgg19-0000.params'},
      'imagenet1k-inception-bn': {'symbol':_base_model_url+'imagenet/inception-bn/Inception-BN-symbol.json',
                               'params':_base_model_url+'imagenet/inception-bn/Inception-BN-0126.params'},
      'imagenet1k-inception-v3': {'symbol':_dummy_model_url+'inception-v3-symbol.json',
                                  'params':_dummy_model_url+'inception-v3-0000.params'},
      'imagenet1k-resnet-18': {'symbol':_base_model_url+'imagenet/resnet/18-layers/resnet-18-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/18-layers/resnet-18-0000.params'},
      'imagenet1k-resnet-34': {'symbol':_base_model_url+'imagenet/resnet/34-layers/resnet-34-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/34-layers/resnet-34-0000.params'},
      'imagenet1k-resnet-50': {'symbol':_base_model_url+'imagenet/resnet/50-layers/resnet-50-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/50-layers/resnet-50-0000.params'},
      'imagenet1k-resnet-101': {'symbol':_base_model_url+'imagenet/resnet/101-layers/resnet-101-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/101-layers/resnet-101-0000.params'},
      'imagenet1k-resnet-152': {'symbol':_base_model_url+'imagenet/resnet/152-layers/resnet-152-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/152-layers/resnet-152-0000.params'},
      'imagenet1k-resnet-200': {'symbol':_base_model_url+'imagenet/resnet/200-layers/resnet-200-symbol.json',
                               'params':_base_model_url+'imagenet/resnet/200-layers/resnet-200-0000.params'},
      'imagenet1k-densenet-169': {'symbol':_dummy_model_url+'imagenet1k-densenet-169-symbol.json',
                                  'params':_dummy_model_url+'imagenet1k-densenet-169-0000.params'},
      'imagenet1k-se-resnext-50': {'symbol':_dummy_model_url+'imagenet1k-se-resnext-50-symbol.json',
                                   'params':_dummy_model_url+'imagenet1k-se-resnext-50-0000.params'},
      'imagenet1k-resnext-50': {'symbol':_base_model_url+'imagenet/resnext/50-layers/resnext-50-symbol.json',
                               'params':_base_model_url+'imagenet/resnext/50-layers/resnext-50-0000.params'},
      'imagenet1k-resnext-101': {'symbol':_base_model_url+'imagenet/resnext/101-layers/resnext-101-symbol.json',
                               'params':_base_model_url+'imagenet/resnext/101-layers/resnext-101-0000.params'},
      'imagenet1k-resnext-101-64x4d': {'symbol':_base_model_url+'imagenet/resnext/101-layers/resnext-101-64x4d-symbol.json',
                                       'params':_base_model_url+'imagenet/resnext/101-layers/resnext-101-64x4d-0000.params'},
      'imagenet11k-resnet-152': {'symbol':_base_model_url+'imagenet-11k/resnet-152/resnet-152-symbol.json',
                               'params':_base_model_url+'imagenet-11k/resnet-152/resnet-152-0000.params'},
      'imagenet11k-place365ch-resnet-152': {'symbol':_base_model_url+'imagenet-11k-place365-ch/resnet-152-symbol.json',
                                            'params':_base_model_url+'imagenet-11k-place365-ch/resnet-152-0000.params'},
      'imagenet11k-place365ch-resnet-50': {'symbol':_base_model_url+'imagenet-11k-place365-ch/resnet-50-symbol.json',
                                           'params':_base_model_url+'imagenet-11k-place365-ch/resnet-50-0000.params'},
  }
  
  def download_model(model_name, dst_dir='./', meta_info=None):
      if meta_info is None:
          meta_info = _default_model_info
      meta_info = dict(meta_info)
      if model_name not in meta_info:
          return (None, 0)
      if not os.path.isdir(dst_dir):
          os.mkdir(dst_dir)
      meta = dict(meta_info[model_name])
      assert 'symbol' in meta, "missing symbol url"
      model_name = os.path.join(dst_dir, model_name)
      download_file(meta['symbol'], model_name+'-symbol.json')
      assert 'params' in meta, "mssing parameter file url"
      download_file(meta['params'], model_name+'-0000.params')
      return (model_name, 0)
  
  
  if __name__ == '__main__':
      import sys
      if len(sys.argv) == 3:
          model_name = sys.argv[1]
          dst_dir = sys.argv[2]
          download_model(model_name, dst_dir)
  