All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.djl.repository.zoo.DefaultModelZoo Maven / Gradle / Ivy

There is a newer version: 0.30.0
Show newest version
/*
 * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
 * with the License. A copy of the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * or in the "license" file accompanying this file. This file 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.
 */
package ai.djl.repository.zoo;

import ai.djl.engine.Engine;
import ai.djl.repository.MRL;
import ai.djl.repository.Repository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/** A {@link ModelZoo} that contains models in specified locations. */
public class DefaultModelZoo implements ModelZoo {

    public static final String GROUP_ID = "ai.djl.localmodelzoo";

    private List> modelLoaders;

    /**
     * Creates the {@code LocalModelZoo} instance from the given search locations.
     *
     * @param locations a comma separated urls where the models to be loaded from
     */
    public DefaultModelZoo(String locations) {
        String[] urls = locations.split("\\s*,\\s*");
        modelLoaders = new ArrayList<>(urls.length);
        for (String url : urls) {
            if (!url.isEmpty()) {
                Repository repo = Repository.newInstance(url, url);
                List mrls = repo.getResources();
                for (MRL mrl : mrls) {
                    modelLoaders.add(new DefaultModelLoader(repo, mrl));
                }
            }
        }
    }

    /** {@inheritDoc} */
    @Override
    public List> getModelLoaders() {
        return modelLoaders;
    }

    /** {@inheritDoc} */
    @Override
    public String getGroupId() {
        return GROUP_ID;
    }

    /** {@inheritDoc} */
    @Override
    public Set getSupportedEngines() {
        return Collections.singleton(Engine.getInstance().getEngineName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy