def _buildTFGraphForName(name, featurize):
    """
    Currently only supports pre-trained models from the Keras applications module.
    """
    modelData = keras_apps.getKerasApplicationModel(name).getModelData(featurize)
    sess = modelData["session"]
    outputTensorName = modelData["outputTensorName"]
    graph = tfx.strip_and_freeze_until([outputTensorName], sess.graph, sess, return_graph=True)
    modelData["graph"] = graph
    return modelData
def _buildTFGraphForName(name, featurize):
    """
    Currently only supports pre-trained models from the Keras applications module.
    """
    modelData = keras_apps.getKerasApplicationModel(name).getModelData(featurize)
    sess = modelData["session"]
    outputTensorName = modelData["outputTensorName"]
    graph = tfx.strip_and_freeze_until([outputTensorName], sess.graph, sess, return_graph=True)
    modelData["graph"] = graph
    return modelData
Esempio n. 3
0
def _buildTFGraphForName(name, featurize):
    if name not in keras_apps.KERAS_APPLICATION_MODELS:
        raise ValueError(
            "%s is not a supported model. Supported models: %s" % name,
            str(KERAS_APPLICATION_MODELS))

    modelData = keras_apps.getKerasApplicationModel(name).getModelData(
        featurize)
    sess = modelData["session"]
    outputTensorName = modelData["outputTensorName"]
    graph = tfx.strip_and_freeze_until([outputTensorName],
                                       sess.graph,
                                       sess,
                                       return_graph=True)
    modelData["graph"] = graph

    return modelData
    def setUpClass(cls):
        super(NamedImageTransformerBaseTestCase, cls).setUpClass()
        cls.appModel = keras_apps.getKerasApplicationModel(cls.name)
        imgFiles, imageArray = cls.getSampleImageList()
        cls.imageArray = imageArray
        cls.imgFiles = imgFiles
        cls.fileOrder = {imgFiles[i].split('/')[-1]: i for i in range(len(imgFiles))}
        # Predict the class probabilities for the images in our test library using keras API
        # and cache for use by multiple tests.
        preppedImage = cls.appModel._testPreprocess(imageArray.astype('float32'))
        cls.preppedImage = preppedImage
        cls.kerasPredict = cls.appModel._testKerasModel(
            include_top=True).predict(preppedImage, batch_size=1)
        cls.kerasFeatures = cls.appModel._testKerasModel(include_top=False).predict(preppedImage)

        cls.imageDF = getSampleImageDF().limit(5)
        if(cls.numPartitionsOverride):
            cls.imageDf = cls.imageDF.coalesce(cls.numPartitionsOverride)
Esempio n. 5
0
    def setUpClass(cls):
        super(NamedImageTransformerBaseTestCase, cls).setUpClass()

        imgFiles, images = getSampleImageList()
        imageArray = np.empty((len(images), 299, 299, 3), 'uint8')
        for i, img in enumerate(images):
            assert img is not None and img.mode == "RGB"
            imageArray[i] = np.array(img.resize((299, 299)))
        cls.imageArray = imageArray

        # Predict the class probabilities for the images in our test library using keras API
        # and cache for use by multiple tests.
        cls.appModel = keras_apps.getKerasApplicationModel(cls.name)
        preppedImage = cls.appModel.preprocess(imageArray.astype('float32'))
        kerasPredict = cls.appModel.testKerasModel().predict(preppedImage)
        cls.kerasPredict = kerasPredict

        cls.imageDF = getSampleImageDF().limit(5)
    def setUpClass(cls):
        super(NamedImageTransformerBaseTestCase, cls).setUpClass()

        cls.appModel = keras_apps.getKerasApplicationModel(cls.name)
        shape = cls.appModel.inputShape()

        imgFiles, images = getSampleImageList()
        imageArray = np.empty((len(images), shape[0], shape[1], 3), 'uint8')
        for i, img in enumerate(images):
            assert img is not None and img.mode == "RGB"
            imageArray[i] = np.array(img.resize(shape))
        cls.imageArray = imageArray

        # Predict the class probabilities for the images in our test library using keras API
        # and cache for use by multiple tests.
        preppedImage = cls.appModel._testPreprocess(imageArray.astype('float32'))
        cls.kerasPredict = cls.appModel._testKerasModel(include_top=True).predict(preppedImage)
        cls.kerasFeatures = cls.appModel._testKerasModel(include_top=False).predict(preppedImage)

        cls.imageDF = getSampleImageDF().limit(5)