Closed qqaazz0222 closed 3 months ago
_/System_Integration/HAR/HRI/emotion.py line:35
detector = face_detection.build_detector(args.face_detector, confidence_threshold=.5, nms_iou_threshold=.3)
위 파일에서 디텍터를 생성할 때, 모델 이름을 통해 torch hub에서 가중치 파일을 다운로드 설정된 다운로드 주소에 접근이 불가능함.
__/opt/conda/lib/python3.10/site-packages/torch/hub.py func:load_state_dict_fromurl
def load_state_dict_from_url(
url: str,
model_dir: Optional[str] = None,
map_location: MAP_LOCATION = None,
progress: bool = True,
check_hash: bool = False,
file_name: Optional[str] = None,
weights_only: bool = False,
) -> Dict[str, Any]:
r"""Loads the Torch serialized object at the given URL.
If downloaded file is a zip file, it will be automatically
decompressed.
If the object is already present in `model_dir`, it's deserialized and
returned.
The default value of ``model_dir`` is ``<hub_dir>/checkpoints`` where
``hub_dir`` is the directory returned by :func:`~torch.hub.get_dir`.
Args:
url (str): URL of the object to download
model_dir (str, optional): directory in which to save the object
map_location (optional): a function or a dict specifying how to remap storage locations (see torch.load)
progress (bool, optional): whether or not to display a progress bar to stderr.
Default: True
check_hash(bool, optional): If True, the filename part of the URL should follow the naming convention
``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more
digits of the SHA256 hash of the contents of the file. The hash is used to
ensure unique names and to verify the contents of the file.
Default: False
file_name (str, optional): name for the downloaded file. Filename from ``url`` will be used if not set.
weights_only(bool, optional): If True, only weights will be loaded and no complex pickled objects.
Recommended for untrusted sources. See :func:`~torch.load` for more details.
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')
"""
# Issue warning to move data if old env is set
if os.getenv('TORCH_MODEL_ZOO'):
warnings.warn('TORCH_MODEL_ZOO is deprecated, please use env TORCH_HOME instead')
if model_dir is None:
hub_dir = get_dir()
model_dir = os.path.join(hub_dir, 'checkpoints')
try:
os.makedirs(model_dir)
except OSError as e:
if e.errno == errno.EEXIST:
# Directory already exists, ignore.
pass
else:
# Unexpected OSError, re-raise.
raise
parts = urlparse(url)
filename = os.path.basename(parts.path)
if file_name is not None:
filename = file_name
cached_file = os.path.join(model_dir, filename)
if not os.path.exists(cached_file): **<<< 이쪽을 활용**
sys.stderr.write(f'Downloading: "{url}" to {cached_file}\n')
hash_prefix = None
if check_hash:
r = HASH_REGEX.search(filename) # r is Optional[Match[str]]
hash_prefix = r.group(1) if r else None
download_url_to_file(url, cached_file, hash_prefix, progress=progress)
if _is_legacy_zip_format(cached_file):
return _legacy_zip_load(cached_file, model_dir, map_location, weights_only)
return torch.load(cached_file, map_location=map_location, weights_only=weights_only)
위 함수에서 캐시된 파일이 있으면, 다운로드하지 않고 캐시된 파일을 사용하는 것을 확인 캐시 경로에 Resnet50_Final.pth을 복사해 두는 것으로 문제 해결
setting.sh에 아래 명령어 추가
cp /System_Integration/_HAR/HRI/models/Resnet50_Final.pth /root/.cache/torch/hub/checkpoints/
얼굴 감지 가중치 불러올때 오류 발생
Resnet50_Final.pth