Beispiel #1
0
def infer(model, directory):
    """  infer a set of images for classification"""
    click.clear()
    click.echo()
    click.echo(lr.APP_TITLE)

    fm = FileManager()
    directory = fm.adjustDirectoryPath(directory)
    logTrainer = LogisticImageTrainer()
    if os.path.exists(lr.LOCAL_SAVED_MODEL_LR):
        logTrainer.loadModel(lr.LOCAL_SAVED_MODEL_LR)
        print("== model", lr.LOCAL_SAVED_MODEL_LR, "loaded")
        it = ImageTools()
        imageList = fm.folderFileListOfImages(directory)
        if len(imageList) > 0:
            for filename in imageList:
                code,descr = logTrainer.infer(directory,filename)
                out = "== FILE {0:s} Class {1:s}->{2:s}".format(filename, code ,descr)
                click.echo(out)
            for filename in imageList:
                code,descr = logTrainer.infer(directory,filename)
                
                out = "== {0:s} -> {1:s}".format( code ,descr)
                it.showImage(directory+filename,out)
        else:
            click.echo(':: No files in \'%s\' directory' % directory)
    else:
        print("== model", lr.LOCAL_SAVED_MODEL_LR, "required for predictions do not exist!")
Beispiel #2
0
    def infer(self, path, filename):
        """Allows to infer on an image, based on a saved model
        """
        fm = FileManager()
        path = fm.adjustDirectoryPath(path)

        it = ImageTools()
        newfile = it.resize(path, filename, lr.IMAGE_RESIZE_ROWS,
                            lr.IMAGE_RESIZE_COLS)
        imgArray = []
        imgArray.append(it.getImageArray(path, newfile))
        os.remove(path + newfile)
        prediction = str(self.__model.predict(imgArray)[0])
        description = self.__CLassDic[prediction]
        return prediction, description
Beispiel #3
0
 def __loadSet(self, path):
     """Given a directory with images, load all images as set.
        Set can be use later as a train or test set
     """
     self.__deleteSets()
     self.__tempoDataSet = []
     self.__tempoLabelSet = []
     fm = FileManager()
     path = fm.adjustDirectoryPath(path)
     imageList = fm.folderFileListOfImages(path)
     it = ImageTools()
     for filename in imageList:
         imgArray = it.getImageArray(path, filename)
         parts = filename.split('_')
         IdClass = int(parts[0])
         self.__tempoDataSet.append(imgArray)
         self.__tempoLabelSet.append(IdClass)