首页 > V2EX > V2EX-新人请教一下怎么添加判断
2021
11-26

V2EX-新人请教一下怎么添加判断

toyst:

原代码:

def extract_features(img_dir, model):
    try:
        cache = Cache('./tmp')
        feats = []
        names = []
        img_list = get_imgs(img_dir)
        total = len(img_list)
        cache['total'] = total
        for i, img_path in enumerate(img_list):
            try:
                norm_feat = model.resnet50_extract_feat(img_path)
                feats.append(norm_feat)
                names.append(img_path.encode())
                cache['current'] = i + 1
                print(f"Extracting feature from image No. {i + 1} , {total} images in total")
            except Exception as e:
                LOGGER.error(f"Error with extracting feature from image {e}")
                continue
        return feats, names
    except Exception as e:
        LOGGER.error(f"Error with extracting feature from image {e}")
        sys.exit(1)

大概位置是下面这里:

def extract_features(img_dir, model):
    try:
        cache = Cache('./tmp')
        feats = []
        names = []
        img_list = get_imgs(img_dir)
        total = len(img_list)
        cache['total'] = total
        #check if img_dir is a image or image_path
        #if it is image, create embedding and return, else, traverse the directory
        for i, img_path in enumerate(img_list):
            #extract feature
        return feats, names
    except Exception as e:
        LOGGER.error(f"Error with extracting feature from image {e}")
        sys.exit(1)

请问一下应该如何写啊?
判断传入的是图片文件名还是目录

from V2EX-最新主题 https://ift.tt/3p5gTLa
V2EX-新人请教一下怎么添加判断 - 第1张  | 牛C网(NiuL.Net)
牛C网:https://niuc.net
零九导航:https://09.gay

最后编辑:
作者:分享菌
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。