Esempio n. 1
0
def main() -> None:
    args = get_args()

    experiment_folder_path: Text = args.out_folder
    if not os.path.exists(experiment_folder_path):
        os.makedirs(experiment_folder_path)

    logging_utils.setup_logging(
        os.path.join(
            experiment_folder_path,
            "log-{}.txt".format(datetime.now().strftime("%Y_%m_%d-%H_%M_%S")),
        ))

    logger = logging_utils.get_logger(__name__)
    logger.info(args)

    model_config_or_checkpoint: Union[model_config_utils.ModelConfig, Text]
    if args.model_config:
        model_config_or_checkpoint = model_config_utils.get_config_from_file(
            args.model_config)
    elif args.checkpoint:
        model_config_or_checkpoint = args.checkpoint
    else:
        err_msg = "Either --model_config or --checkpoint must be provided."
        logger.error(err_msg)
        raise ValueError(err_msg)

    train_config: train_config_utils.TrainConfig = train_config_utils.get_config_from_file(
        args.train_config)

    with torch.cuda.device(args.cuda_device_id):
        train_model_with_configs(
            model_config_or_checkpoint=model_config_or_checkpoint,
            train_config=train_config,
            experiment_folder_path=experiment_folder_path,
            resume_training=args.resume_training,
            save_interval=args.save_interval,
            save_best_checkpoint=args.save_best_checkpoint,
            use_gpu=not args.no_cuda,
        )
Esempio n. 2
0
def main() -> None:
    args = get_args()

    config: prune_config_utils.PruneConfig = prune_config_utils.get_config_from_file(
        args.config)
    pruned_output_folder: Text = (args.out_folder if args.out_folder else
                                  config.pruned_model_out_folder)

    # Logging
    datetime_string: Text = datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
    logging_utils.setup_logging(log_file_loc=os.path.join(
        pruned_output_folder,
        FILE_NAME_FORMAT_LOG.format(datetime_string),
    ))
    logger = logging_utils.get_logger(LOGGER_NAME)
    logger.info(args)

    prune_network(
        prune_config=config,
        pruned_output_folder=pruned_output_folder,
        model_checkpoint_path=args.model,
    )
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# **************************************************************************/

import logging
from os import path
from utils.file_utils import read_json
from feed.feed_request import Feed
from filter.feed_filter import FeedFilterRequest
from constants.feed_constants import SUCCESS_CODE
from enums.config_enums import ConfigField, FeedField, FilterField
from errors.custom_exceptions import ConfigError
from utils.logging_utils import setup_logging

setup_logging()
logger = logging.getLogger(__name__)


class ConfigRequest(object):
    def __init__(self, feed_obj, filter_request_obj):
        self.feed_obj = feed_obj
        self.filter_request_obj = filter_request_obj

    def __str__(self):
        return '[feed= %s, filter_request= %s]' % (self.feed_obj,
                                                   self.filter_request_obj)


class ConfigFileRequest(object):
    def __init__(self, config_file_path):