trains/model.py
def update_weights_package(self, weights_filenames=None, weights_path=None, upload_uri=None,
                               target_filename=None, auto_delete_file=True, iteration=None):
        """
        Update the model weights from a locally stored model files (or directory containing multiple files).

        Uploading the model is a background process, the call returns immediately.

        :param weights_filenames: list of locally stored filenames (list of strings)
        :type weights_filenames: list
        :param weights_path: directory path to package (all the files in the directory will be uploaded)
        :type weights_path: str
        :param upload_uri: destination uri for model weights upload (default: previously used uri)
        :param target_filename: the newly created filename in the destination uri location (default: weights_filename)
        :param auto_delete_file: delete temporary file after uploading
        :return: uploaded uri for the weights package
        """
        # create list of files
        if (not weights_filenames and not weights_path) or (weights_filenames and weights_path):
            raise ValueError('Model update weights package should get either directory path to pack or a list of files')

        if not weights_filenames:
            weights_filenames = list(map(six.text_type, Path(weights_path).glob('*')))

        # create packed model from all the files
        fd, zip_file = mkstemp(prefix='model_package.', suffix='.zip')
        try:
            with zipfile.ZipFile(zip_file, 'w', allowZip64=True, compression=zipfile.ZIP_STORED) as zf:
                for filename in weights_filenames:
                    zf.write(filename, arcname=Path(filename).name)
        finally:
            os.close(fd)

        # now we can delete the files (or path if provided)
        if auto_delete_file:
            def safe_remove(path, is_dir=False):
                try:
                    (os.rmdir if is_dir else os.remove)(path)
                except OSError:
                    self._log.info('Failed removing temporary {}'.format(path))

            for filename in weights_filenames:
                safe_remove(filename)
            if weights_path:
                safe_remove(weights_path, is_dir=True)

        if target_filename and not target_filename.lower().endswith('.zip'):
            target_filename += '.zip'

        # and now we should upload the file, always delete the temporary zip file
        comment = self.comment or ''
        iteration_msg = 'snapshot {} stored'.format(str(weights_filenames))
        if not comment.startswith('\n'):
            comment = '\n' + comment
        comment = iteration_msg + comment
        self.comment = comment
        uploaded_uri = self.update_weights(weights_filename=zip_file, auto_delete_file=True, upload_uri=upload_uri,
                                           target_filename=target_filename or 'model_package.zip',
                                           iteration=iteration, update_comment=False)
        # set the model tag (by now we should have a model object) so we know we have packaged file
        self._set_package_tag()
        return uploaded_uri

        Update the model weights from a locally stored model files (or directory containing multiple files).

        Uploading the model is a background process, the call returns immediately.

        :param weights_filenames: list of locally stored filenames (list of strings)
        :type weights_filenames: list
        :param weights_path: directory path to package (all the files in the directory will be uploaded)
        :type weights_path: str
        :param upload_uri: destination uri for model weights upload (default: previously used uri)
        :param target_filename: the newly created filename in the destination uri location (default: weights_filename)
        :param auto_delete_file: delete temporary file after uploading
        :return: uploaded uri for the weights package
        
Update the model weights from a locally stored model files (or directory containing multiple files).
Uploading the model is a background process, the call returns immediately.
Update the model weights from a locally stored model files ( or directory containing multiple files ) . Uploading the model is a background process the call returns immediately .
def update_weights_package(self, weights_filenames=None, weights_path=None, upload_uri=None,
                               target_filename=None, auto_delete_file=True, iteration=None):
        if (not weights_filenames and not weights_path) or (weights_filenames and weights_path):
            raise ValueError('Model update weights package should get either directory path to pack or a list of files')
        if not weights_filenames:
            weights_filenames = list(map(six.text_type, Path(weights_path).glob('*')))
        fd, zip_file = mkstemp(prefix='model_package.', suffix='.zip')
        try:
            with zipfile.ZipFile(zip_file, 'w', allowZip64=True, compression=zipfile.ZIP_STORED) as zf:
                for filename in weights_filenames:
                    zf.write(filename, arcname=Path(filename).name)
        finally:
            os.close(fd)
        if auto_delete_file:
            def safe_remove(path, is_dir=False):
                try:
                    (os.rmdir if is_dir else os.remove)(path)
                except OSError:
                    self._log.info('Failed removing temporary {}'.format(path))
            for filename in weights_filenames:
                safe_remove(filename)
            if weights_path:
                safe_remove(weights_path, is_dir=True)
        if target_filename and not target_filename.lower().endswith('.zip'):
            target_filename += '.zip'
        comment = self.comment or ''
        iteration_msg = 'snapshot {} stored'.format(str(weights_filenames))
        if not comment.startswith('\n'):
            comment = '\n' + comment
        comment = iteration_msg + comment
        self.comment = comment
        uploaded_uri = self.update_weights(weights_filename=zip_file, auto_delete_file=True, upload_uri=upload_uri,
                                           target_filename=target_filename or 'model_package.zip',
                                           iteration=iteration, update_comment=False)
        self._set_package_tag()
        return uploaded_uri
def update_weights_package ( self , weights_filenames = None , weights_path = None , upload_uri = None , target_filename = None , auto_delete_file = True , iteration = None ) : if ( not weights_filenames and not weights_path ) or ( weights_filenames and weights_path ) : raise ValueError ( 'Model update weights package should get either directory path to pack or a list of files' ) if not weights_filenames : weights_filenames = list ( map ( six . text_type , Path ( weights_path ) . glob ( '*' ) ) ) fd , zip_file = mkstemp ( prefix = 'model_package.' , suffix = '.zip' ) try : with zipfile . ZipFile ( zip_file , 'w' , allowZip64 = True , compression = zipfile . ZIP_STORED ) as zf : for filename in weights_filenames : zf . write ( filename , arcname = Path ( filename ) . name ) finally : os . close ( fd ) if auto_delete_file : def safe_remove ( path , is_dir = False ) : try : ( os . rmdir if is_dir else os . remove ) ( path ) except OSError : self . _log . info ( 'Failed removing temporary {}' . format ( path ) ) for filename in weights_filenames : safe_remove ( filename ) if weights_path : safe_remove ( weights_path , is_dir = True ) if target_filename and not target_filename . lower ( ) . endswith ( '.zip' ) : target_filename += '.zip' comment = self . comment or '' iteration_msg = 'snapshot {} stored' . format ( str ( weights_filenames ) ) if not comment . startswith ( '\n' ) : comment = '\n' + comment comment = iteration_msg + comment self . comment = comment uploaded_uri = self . update_weights ( weights_filename = zip_file , auto_delete_file = True , upload_uri = upload_uri , target_filename = target_filename or 'model_package.zip' , iteration = iteration , update_comment = False ) self . _set_package_tag ( ) return uploaded_uri
Update the model weights from a locally stored model files (or directory containing multiple files).
Update the model weights from a locally stored model files ( or directory containing multiple files ) .
"""
        Update the model weights from a locally stored model files (or directory containing multiple files).

        Uploading the model is a background process, the call returns immediately.

        :param weights_filenames: list of locally stored filenames (list of strings)
        :type weights_filenames: list
        :param weights_path: directory path to package (all the files in the directory will be uploaded)
        :type weights_path: str
        :param upload_uri: destination uri for model weights upload (default: previously used uri)
        :param target_filename: the newly created filename in the destination uri location (default: weights_filename)
        :param auto_delete_file: delete temporary file after uploading
        :return: uploaded uri for the weights package
        """ # create list of files # create packed model from all the files # now we can delete the files (or path if provided) # and now we should upload the file, always delete the temporary zip file # set the model tag (by now we should have a model object) so we know we have packaged file
uploaded uri for the weights package
uploaded uri for the weights package
self
weights_filenames
list of locally stored filenames (list of strings)
list of locally stored filenames ( list of strings )
weights_path
directory path to package (all the files in the directory will be uploaded)
directory path to package ( all the files in the directory will be uploaded )
upload_uri
destination uri for model weights upload (default: previously used uri)
destination uri for model weights upload ( default : previously used uri )
target_filename
the newly created filename in the destination uri location (default: weights_filename)
the newly created filename in the destination uri location ( default : weights_filename )
auto_delete_file
delete temporary file after uploading
delete temporary file after uploading
iteration