lambda-multilabel/pytorch/app.py
def load_model():
    """Loads the PyTorch model into memory from a file on S3.

    Returns
    ------
    Vision model: Module
        Returns the vision PyTorch model to use for inference.
    
    """      
    global classes
    #global 
    
    #thresholds = THRESHOLD_VALUES # Above needs
    logger.info("**load_model**")
    obj = s3.get_object(Bucket=MODEL_BUCKET, Key=MODEL_KEY)
    bytestream = io.BytesIO(obj['Body'].read())
    tar = tarfile.open(fileobj=bytestream, mode="r:gz")
    for member in tar.getmembers():
        if member.name.endswith(".txt"):
            print("Classes file is :", member.name)
            f=tar.extractfile(member)
            classes = f.read().splitlines()
            print(classes)
        if member.name.endswith(".pth"):
            print("Model file is :", member.name)
            f=tar.extractfile(member)
            print("Loading PyTorch model")
            model = torch.jit.load(io.BytesIO(f.read()), map_location=torch.device('cpu')).eval()
    return model
Loads the PyTorch model into memory from a file on S3.

    Returns
    ------
    Vision model: Module
        Returns the vision PyTorch model to use for inference.
    
    
Loads the PyTorch model into memory from a file on S3.
Returns

Vision model: Module
Returns the vision PyTorch model to use for inference.
Loads the PyTorch model into memory from a file on S3 . Returns Vision model : Module Returns the vision PyTorch model to use for inference .
def load_model():
    global classes
    logger.info("**load_model**")
    obj = s3.get_object(Bucket=MODEL_BUCKET, Key=MODEL_KEY)
    bytestream = io.BytesIO(obj['Body'].read())
    tar = tarfile.open(fileobj=bytestream, mode="r:gz")
    for member in tar.getmembers():
        if member.name.endswith(".txt"):
            print("Classes file is :", member.name)
            f=tar.extractfile(member)
            classes = f.read().splitlines()
            print(classes)
        if member.name.endswith(".pth"):
            print("Model file is :", member.name)
            f=tar.extractfile(member)
            print("Loading PyTorch model")
            model = torch.jit.load(io.BytesIO(f.read()), map_location=torch.device('cpu')).eval()
    return model
def load_model ( ) : global classes logger . info ( "**load_model**" ) obj = s3 . get_object ( Bucket = MODEL_BUCKET , Key = MODEL_KEY ) bytestream = io . BytesIO ( obj [ 'Body' ] . read ( ) ) tar = tarfile . open ( fileobj = bytestream , mode = "r:gz" ) for member in tar . getmembers ( ) : if member . name . endswith ( ".txt" ) : print ( "Classes file is :" , member . name ) f = tar . extractfile ( member ) classes = f . read ( ) . splitlines ( ) print ( classes ) if member . name . endswith ( ".pth" ) : print ( "Model file is :" , member . name ) f = tar . extractfile ( member ) print ( "Loading PyTorch model" ) model = torch . jit . load ( io . BytesIO ( f . read ( ) ) , map_location = torch . device ( 'cpu' ) ) . eval ( ) return model
Loads the PyTorch model into memory from a file on S3.
Loads the PyTorch model into memory from a file on S3 .
"""Loads the PyTorch model into memory from a file on S3.

    Returns
    ------
    Vision model: Module
        Returns the vision PyTorch model to use for inference.
    
    """ #global  #thresholds = THRESHOLD_VALUES # Above needs