trains/model.py
def update_weights(self, weights_filename=None, upload_uri=None, target_filename=None,
                       auto_delete_file=True, register_uri=None, iteration=None, update_comment=True):
        """
        Update the model weights from a locally stored model filename.

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

        :param weights_filename: locally stored filename to be uploaded as is
        :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
        :param register_uri: register an already uploaded weights file (uri must be valid)
        :param update_comment: if True, model comment will be updated with local weights file location (provenance)
        :return: uploaded uri
        """

        def delete_previous_weights_file(filename=weights_filename):
            try:
                if filename:
                    os.remove(filename)
            except OSError:
                self._log.debug('Failed removing temporary file %s' % filename)

        # test if we can update the model
        if self.id and self.published:
            raise ValueError('Model is published and cannot be changed')

        if (not weights_filename and not register_uri) or (weights_filename and register_uri):
            raise ValueError('Model update must have either local weights file to upload, '
                             'or pre-uploaded register_uri, never both')

        # only upload if we are connected to a task
        if not self._task:
            raise Exception('Missing a task for this model')

        if weights_filename is not None:
            # make sure we delete the previous file, if it exists
            if self._model_local_filename != weights_filename:
                delete_previous_weights_file(self._model_local_filename)
            # store temp filename for deletion next time, if needed
            if auto_delete_file:
                self._model_local_filename = weights_filename

        # make sure the created model is updated:
        model = self._get_force_base_model()
        if not model:
            raise ValueError('Failed creating internal output model')

        # select the correct file extension based on the framework, or update the framework based on the file extension
        framework, file_ext = Framework._get_file_ext(
            framework=self._get_model_data().framework,
            filename=weights_filename or register_uri
        )

        if weights_filename:
            target_filename = target_filename or Path(weights_filename).name
            if not target_filename.lower().endswith(file_ext):
                target_filename += file_ext

        # set target uri for upload (if specified)
        if upload_uri:
            self.set_upload_destination(upload_uri)

        # let us know the iteration number, we put it in the comment section for now.
        if update_comment:
            comment = self.comment or ''
            iteration_msg = 'snapshot {} stored'.format(weights_filename or register_uri)
            if not comment.startswith('\n'):
                comment = '\n' + comment
            comment = iteration_msg + comment
        else:
            comment = None

        # if we have no output destination, just register the local model file
        if weights_filename and not self.upload_storage_uri and not self._task.storage_uri:
            register_uri = weights_filename
            weights_filename = None
            auto_delete_file = False
            self._log.info('No output storage destination defined, registering local model %s' % register_uri)

        # start the upload
        if weights_filename:
            if not model.upload_storage_uri:
                self.set_upload_destination(self.upload_storage_uri or self._task.storage_uri)

            output_uri = model.update_and_upload(
                model_file=weights_filename,
                task_id=self._task.id,
                async_enable=True,
                target_filename=target_filename,
                framework=self.framework or framework,
                comment=comment,
                cb=delete_previous_weights_file if auto_delete_file else None,
                iteration=iteration or self._task.data.last_iteration,
            )
        elif register_uri:
            register_uri = StorageHelper.conform_url(register_uri)
            output_uri = model.update(uri=register_uri, task_id=self._task.id, framework=framework, comment=comment)
        else:
            output_uri = None

        # make sure that if we are in dev move we report that we are training (not debugging)
        self._task._output_model_updated()

        return output_uri

        Update the model weights from a locally stored model filename.

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

        :param weights_filename: locally stored filename to be uploaded as is
        :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
        :param register_uri: register an already uploaded weights file (uri must be valid)
        :param update_comment: if True, model comment will be updated with local weights file location (provenance)
        :return: uploaded uri
        
Update the model weights from a locally stored model filename.
Uploading the model is a background process, the call returns immediately.
Update the model weights from a locally stored model filename . Uploading the model is a background process the call returns immediately .
def update_weights(self, weights_filename=None, upload_uri=None, target_filename=None,
                       auto_delete_file=True, register_uri=None, iteration=None, update_comment=True):
        def delete_previous_weights_file(filename=weights_filename):
            try:
                if filename:
                    os.remove(filename)
            except OSError:
                self._log.debug('Failed removing temporary file %s' % filename)
        if self.id and self.published:
            raise ValueError('Model is published and cannot be changed')
        if (not weights_filename and not register_uri) or (weights_filename and register_uri):
            raise ValueError('Model update must have either local weights file to upload, '
                             'or pre-uploaded register_uri, never both')
        if not self._task:
            raise Exception('Missing a task for this model')
        if weights_filename is not None:
            if self._model_local_filename != weights_filename:
                delete_previous_weights_file(self._model_local_filename)
            if auto_delete_file:
                self._model_local_filename = weights_filename
        model = self._get_force_base_model()
        if not model:
            raise ValueError('Failed creating internal output model')
        framework, file_ext = Framework._get_file_ext(
            framework=self._get_model_data().framework,
            filename=weights_filename or register_uri
        )
        if weights_filename:
            target_filename = target_filename or Path(weights_filename).name
            if not target_filename.lower().endswith(file_ext):
                target_filename += file_ext
        if upload_uri:
            self.set_upload_destination(upload_uri)
        if update_comment:
            comment = self.comment or ''
            iteration_msg = 'snapshot {} stored'.format(weights_filename or register_uri)
            if not comment.startswith('\n'):
                comment = '\n' + comment
            comment = iteration_msg + comment
        else:
            comment = None
        if weights_filename and not self.upload_storage_uri and not self._task.storage_uri:
            register_uri = weights_filename
            weights_filename = None
            auto_delete_file = False
            self._log.info('No output storage destination defined, registering local model %s' % register_uri)
        if weights_filename:
            if not model.upload_storage_uri:
                self.set_upload_destination(self.upload_storage_uri or self._task.storage_uri)
            output_uri = model.update_and_upload(
                model_file=weights_filename,
                task_id=self._task.id,
                async_enable=True,
                target_filename=target_filename,
                framework=self.framework or framework,
                comment=comment,
                cb=delete_previous_weights_file if auto_delete_file else None,
                iteration=iteration or self._task.data.last_iteration,
            )
        elif register_uri:
            register_uri = StorageHelper.conform_url(register_uri)
            output_uri = model.update(uri=register_uri, task_id=self._task.id, framework=framework, comment=comment)
        else:
            output_uri = None
        self._task._output_model_updated()
        return output_uri
def update_weights ( self , weights_filename = None , upload_uri = None , target_filename = None , auto_delete_file = True , register_uri = None , iteration = None , update_comment = True ) : def delete_previous_weights_file ( filename = weights_filename ) : try : if filename : os . remove ( filename ) except OSError : self . _log . debug ( 'Failed removing temporary file %s' % filename ) if self . id and self . published : raise ValueError ( 'Model is published and cannot be changed' ) if ( not weights_filename and not register_uri ) or ( weights_filename and register_uri ) : raise ValueError ( 'Model update must have either local weights file to upload, ' 'or pre-uploaded register_uri, never both' ) if not self . _task : raise Exception ( 'Missing a task for this model' ) if weights_filename is not None : if self . _model_local_filename != weights_filename : delete_previous_weights_file ( self . _model_local_filename ) if auto_delete_file : self . _model_local_filename = weights_filename model = self . _get_force_base_model ( ) if not model : raise ValueError ( 'Failed creating internal output model' ) framework , file_ext = Framework . _get_file_ext ( framework = self . _get_model_data ( ) . framework , filename = weights_filename or register_uri ) if weights_filename : target_filename = target_filename or Path ( weights_filename ) . name if not target_filename . lower ( ) . endswith ( file_ext ) : target_filename += file_ext if upload_uri : self . set_upload_destination ( upload_uri ) if update_comment : comment = self . comment or '' iteration_msg = 'snapshot {} stored' . format ( weights_filename or register_uri ) if not comment . startswith ( '\n' ) : comment = '\n' + comment comment = iteration_msg + comment else : comment = None if weights_filename and not self . upload_storage_uri and not self . _task . storage_uri : register_uri = weights_filename weights_filename = None auto_delete_file = False self . _log . info ( 'No output storage destination defined, registering local model %s' % register_uri ) if weights_filename : if not model . upload_storage_uri : self . set_upload_destination ( self . upload_storage_uri or self . _task . storage_uri ) output_uri = model . update_and_upload ( model_file = weights_filename , task_id = self . _task . id , async_enable = True , target_filename = target_filename , framework = self . framework or framework , comment = comment , cb = delete_previous_weights_file if auto_delete_file else None , iteration = iteration or self . _task . data . last_iteration , ) elif register_uri : register_uri = StorageHelper . conform_url ( register_uri ) output_uri = model . update ( uri = register_uri , task_id = self . _task . id , framework = framework , comment = comment ) else : output_uri = None self . _task . _output_model_updated ( ) return output_uri
Update the model weights from a locally stored model filename.
Update the model weights from a locally stored model filename .
"""
        Update the model weights from a locally stored model filename.

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

        :param weights_filename: locally stored filename to be uploaded as is
        :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
        :param register_uri: register an already uploaded weights file (uri must be valid)
        :param update_comment: if True, model comment will be updated with local weights file location (provenance)
        :return: uploaded uri
        """ # test if we can update the model # only upload if we are connected to a task # make sure we delete the previous file, if it exists # store temp filename for deletion next time, if needed # make sure the created model is updated: # select the correct file extension based on the framework, or update the framework based on the file extension # set target uri for upload (if specified) # let us know the iteration number, we put it in the comment section for now. # if we have no output destination, just register the local model file # start the upload # make sure that if we are in dev move we report that we are training (not debugging)
None
self
weights_filename
locally stored filename to be uploaded as is
locally stored filename to be uploaded as is
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
register_uri
register an already uploaded weights file (uri must be valid)
register an already uploaded weights file ( uri must be valid )
iteration
update_comment
if True, model comment will be updated with local weights file location (provenance)
if True model comment will be updated with local weights file location ( provenance )