Пример #1
0
def main(argv):

    global model
    global processorOpts

    # Reading and parsing args

    ioOpts, _, _ = osutils.parseArgs(argv)
    
    if ioOpts.modelFolder is None:
        mypprint.printError("Model Folder parameter is not defined")
        sys.exit(2)
    

    if ioOpts.source == chestxrayio.GCP_SOURCE:
        ioOpts.bucket = chestxrayio.getGCPStorageBucket(ioOpts)
    

    # Loading model
    mypprint.printText("Cargando modelo")
    model = chestxrayio.loadModel("model.h5", ioOpts)


    # Loading preprocesing images options

    processorOpts = chestxrayio.loadPreprocesingOpts("parametersSummary.json", ioOpts)


    # Run flask app

    app.run()
Пример #2
0
def createFolder(folderPath):

    if not os.path.isdir(folderPath):
        try:
            os.mkdir(folderPath)
        except OSError as err:
            mypprint.printError("Can not create directory " % folderPath)
            sys.exit(2)
Пример #3
0
def getDataFrom(ioOpts, processorOpts, dataType):

    if ioOpts.source == GCP_SOURCE:
        return getDataFromGCP(dataType, processorOpts, ioOpts)
    elif ioOpts.source == LOCAL_SOURCE:
        return getDataFromLocalDisk(dataType, processorOpts, ioOpts)
    else:
        mypprint.printError("Source " + source + " not known. Can not retrieve data")

    return (np.array([]), np.array([]))
Пример #4
0
def deleteFile(fileName):

    try:
        os.remove(fileName)
    except OSError as e:
        mypprint.printError("Can not delete " + fileName + ". " + str(e))
Пример #5
0
def parseArgs(argv):

    ioOpts = IOOpts()
    processorOpts = ProcessorOpts()
    trainningOpts = TrainingOpts()

    try:
        opts, args = getopt.getopt(argv, 
                                    "hs:n:H:w:e:v:c:k:b:u:f:", 
                                    ["help", 
                                     "source=", 
                                     "normalize=", 
                                     "height=", 
                                     "width=", 
                                     "epochs=", 
                                     "validationSplit=",
                                     "channel=",
                                     "gcpkey=",
                                     "bucket=",
                                     "batch_size=",
                                     "folder="
                                     ]
                                    )
    except getopt.GetoptError as err:
        sys.exit(2)

    for opt, value in opts:

        if opt in ("-h", "--help"):
            mypprint.printText("Read README.md to know more about parameters")
            sys.exit()

        if opt in ("-s", "--source"):
            if value.lower() in ("local", "gcp"):
                ioOpts.source = value
            else:
                mypprint.printError("Source "+ value + " is not known")
                sys.exit(2)
        
        if opt in ("-n", "--normalize"):
            if value.lower() == "no":
                processorOpts.normalize = False
            elif value.lower() == "yes":
                processorOpts.normalize = True
            else:
                mypprint.printError("Normalize image`s pixels option "+ value + " is not known")
                sys.exit(2)
        
        if opt in ("-H", "--height"):
            try:
                processorOpts.height = int(value)
            except ValueError as err:
                mypprint.printError("Height argument not valid.")
                sys.exit(2)

        if opt in ("-w", "--width"):
            try:
                processorOpts.width = int(value)
            except ValueError as err:
                mypprint.printError("Width argument not valid.")
                sys.exit(2)
        
        if opt in ("-e", "--epochs"):
            try:
                trainningOpts.epochs = int(value)
            except ValueError as err:
                mypprint.printError("Epochs argument not valid.")
                sys.exit(2)
        
        if opt in ("-b", "--batch_size"):
            try:
                trainningOpts.batchSize = int(value)
            except ValueError as err:
                mypprint.printError("Batch Size argument not valid.")
                sys.exit(2)

        if opt in ("-v", "--validationSplit"):
            try:
                trainningOpts.validationSplit = float(value)
                if trainningOpts.validationSplit > 1 and trainningOpts.validationSplit < 0:
                    mypprint.printError("Validations split must be a value between 0 and 1")
                    sys.exit(2)
            except ValueError as err:
                mypprint.printError("Validation split argument not valid.")
                sys.exit(2)
            
        if opt in ("-c", "--channel"):
            if value.lower() == "rgb":
                processorOpts.channels = 3
            elif value.lower() == "gray":
                processorOpts.channels = 1
            else:
                sys.exit(2)
        
        if opt in ("-k", "--gcpkey"):
            ioOpts.googleStorageKey = value
        
        if opt in ("-u", "--bucket"):
            ioOpts.bucketName = value
        
        if opt in ("-f", "--folder"):

            if value[-1] == os.sep:
                value = value[:-1]
            ioOpts.modelFolder = value

    return ioOpts, processorOpts, trainningOpts