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

org.bigml.mimir.concurrency.ConcurrencyTest Maven / Gradle / Ivy

The newest version!
package org.bigml.mimir.concurrency;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bigml.mimir.concurrent.ThreadedPredictor;
import org.bigml.mimir.deepnet.network.Network;
import org.bigml.mimir.image.ImageTest;
import org.bigml.mimir.utils.TestUtils;
import org.junit.Test;

public class ConcurrencyTest {
    public void testImages(String netId) {
        Network net = ImageTest.createPretrained(netId);

        File dogFile = TestUtils.getTestFile("dog.jpg");
        File busFile = TestUtils.getTestFile("bus.jpg");
        Map dogPoint = new HashMap();
        Map busPoint = new HashMap();
        dogPoint.put("000000", dogFile);
        busPoint.put("000000", busFile);

        List> pts = new ArrayList>();

        for (int i = 0; i < 4; i++) {
            pts.add(dogPoint);
            pts.add(busPoint);
        }

        double[][] oneCore = new double[8][];
        for (int i = 0; i < pts.size(); i++)
            oneCore[i] = net.predict(pts.get(i));

        ThreadedPredictor pool = new ThreadedPredictor(net, 2);
        double[][] multicore = pool.predict(pts);

        TestUtils.aboutEquals(oneCore, multicore);
    }

    @Test
    public void testResnet18() {
        testImages("resnet18");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy