def test_list_pretrained_models(): models = ff.list_pretrained_models() assert isinstance( models, list), f"returned value must be list but found:{type(models)}" for model in models: assert isinstance( model, str ), f"pretrained model must contain name as string but found:{type(model)}"
def parse_arguments(): ap = argparse.ArgumentParser() ap.add_argument("--model", "-m", type=str, default="original_lffd_560_25L_8S", choices=fastface.list_pretrained_models(), help='pretrained model to be used') ap.add_argument("--device", "-d", type=str, choices=['cpu','cuda'], default='cuda' if torch.cuda.is_available() else 'cpu') ap.add_argument('--partition', '-p', type=str, default='easy', help='widerface partition set', choices=['easy','medium','hard']) return ap.parse_args()
def get_arguments(): ap = argparse.ArgumentParser() ap.add_argument("--model", "-m", type=str, default="original_lffd_560_25L_8S", choices=ff.list_pretrained_models(), help='pretrained model to be used') ap.add_argument("--device", "-d", type=str, choices=['cpu','cuda'], default='cuda' if torch.cuda.is_available() else 'cpu') ap.add_argument('--input', '-i', type=str, required=True, help='image file path') ap.add_argument('--det-threshold', '-dt', type=float, default=.8, help='detection score threshold') ap.add_argument('--iou-threshold', '-it', type=float, default=.4, help='iou score threshold') return ap.parse_args()
@pytest.mark.parametrize("arch,config", list(utils.build_module_args())) def test_module_build(arch: str, config: str): module = ff.FaceDetector.build(arch, config) assert isinstance( module, pl.LightningModule ), "module must be instance of pl.LightningModule but found:{}".format( type(module)) config = ff.get_arch_config(arch, config) module = ff.FaceDetector.build(arch, config) assert isinstance( module, pl.LightningModule ), "module must be instance of pl.LightningModule but found:{}".format( type(module)) @pytest.mark.parametrize("model_name", ff.list_pretrained_models()) def test_module_from_pretrained(model_name: str): module = ff.FaceDetector.from_pretrained(model_name) assert isinstance( module, pl.LightningModule ), "module must be instance of pl.LightningModule but found:{}".format( type(module)) @pytest.mark.parametrize("model_name", ff.list_pretrained_models()) def test_module_from_checkpoint(model_name: str): cache_path = ff.utils.cache.get_model_cache_dir() model_path = os.path.join(cache_path, model_name) if not os.path.exists(model_path):
import fastface as ff import pytorch_lightning as pl import torch # checkout available pretrained models print(ff.list_pretrained_models()) # ["lffd_slim", "lffd_original"] # build pl.LightningModule using pretrained weights model = ff.FaceDetector.from_pretrained("lffd_slim") # set model to eval mode model.eval() # build transforms transforms = ff.transforms.Compose( ff.transforms.Interpolate(target_size=480), ff.transforms.Padding(target_size=(480, 480))) # build torch.utils.data.Dataset ds = ff.dataset.FDDBDataset(phase="test", transforms=transforms) # build torch.utils.data.DataLoader dl = ds.get_dataloader(batch_size=1, num_workers=0) # add average precision pl.metrics.Metric to the model model.add_metric("average_precision", ff.metric.AveragePrecision(iou_threshold=0.5)) # define pl.Trainer for testing trainer = pl.Trainer(benchmark=True,
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. from functools import partial from flash.core.registry import FlashRegistry from flash.core.utilities.imports import _FASTFACE_AVAILABLE if _FASTFACE_AVAILABLE: import fastface as ff _MODEL_NAMES = ff.list_pretrained_models() else: _MODEL_NAMES = [] def fastface_backbone(model_name: str, pretrained: bool, **kwargs): if pretrained: pl_model = ff.FaceDetector.from_pretrained(model_name, **kwargs) else: arch, config = model_name.split("_") pl_model = ff.FaceDetector.build(arch, config, **kwargs) backbone = getattr(pl_model, "arch") return backbone, pl_model
@pytest.mark.parametrize("arch", ff.list_archs()) def test_list_arch_configs(arch: str): arch_configs = ff.list_arch_configs(arch) assert isinstance( arch_configs, list), f"returned value must be list but found:{type(arch_configs)}" for arch_config in arch_configs: assert isinstance( arch_config, str ), f"architecture config must contain string but found:{type(arch_config)}" @pytest.mark.parametrize("arch", ff.list_archs()) def test_get_arch_config(arch: str): arch_configs = ff.list_arch_configs(arch) for arch_config in arch_configs: config = ff.get_arch_config(arch, arch_config) assert isinstance( config, dict ), f"{arch}.{arch_config} must be dictionary but found: {type(config)}" @pytest.mark.parametrize("model_name", ff.list_pretrained_models()) def test_download(model_name: str): model_file_path = ff.download_pretrained_model( model_name, target_path=ff.utils.cache.get_model_cache_dir()) assert os.path.exists( model_file_path), "model file is not exists in {}".format( model_file_path)