lightningdot
copied
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions
49 lines
1.8 KiB
49 lines
1.8 KiB
# Copyright 2021 Zilliz. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# 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.
|
|
import wget
|
|
import torch
|
|
import os
|
|
from types import SimpleNamespace
|
|
from torchvision.datasets.utils import download_url
|
|
|
|
class Configs(SimpleNamespace):
|
|
|
|
def __init__(self, dictionary, **kwargs):
|
|
super().__init__(**kwargs)
|
|
for key, value in dictionary.items():
|
|
if isinstance(value, dict):
|
|
self.__setattr__(key, Configs(value))
|
|
else:
|
|
self.__setattr__(key, value)
|
|
|
|
def __getattribute__(self, value):
|
|
try:
|
|
return super().__getattribute__(value)
|
|
except AttributeError:
|
|
return None
|
|
|
|
def get_gather_index(txt_lens, num_bbs, batch_size, max_len, out_size):
|
|
# assert len(txt_lens) == len(num_bbs) == batch_size
|
|
gather_index = torch.arange(0, out_size, dtype=torch.long,
|
|
).unsqueeze(0).repeat(len(num_bbs), 1)
|
|
|
|
# for i, (tl, nbb) in enumerate(zip(txt_lens, num_bbs)):
|
|
# gather_index.data[i, tl:tl+nbb] = torch.arange(max_len, max_len+nbb,
|
|
# dtype=torch.long).data
|
|
return gather_index
|
|
|
|
def download_file(url, save_path):
|
|
filename = os.path.basename(url)
|
|
download_url(url, save_path, filename)
|
|
|