reuse_weights[k] = v
if isinstance(k, str):
try:
new_idx = self._classes.index(k) // raise ValueError if not found
except ValueError:
raise ValueError(
"{} not found in new class names {}".format(k, self._classes))
After Change
if isinstance(reuse_weights, (dict, list)):
if isinstance(reuse_weights, dict):
// trying to replace str with indices
new_keys = []
new_vals = []
for k, v in reuse_weights.items():
if isinstance(v, str):
try:
new_vals.append(old_classes.index(v)) // raise ValueError if not found
except ValueError:
raise ValueError(
"{} not found in old class names {}".format(v, old_classes))
else:
if v < 0 or v >= len(old_classes):
raise ValueError(
"Index {} out of bounds for old class names".format(v))
new_vals.append(v)
if isinstance(k, str):
try:
new_keys.append(self.classes.index(k)) // raise ValueError if not found
except ValueError:
raise ValueError(
"{} not found in new class names {}".format(k, self.classes))
else:
if k < 0 or k >= len(self.classes):
raise ValueError(
"Index {} out of bounds for new class names".format(k))
new_keys.append(k)
reuse_weights = dict(zip(new_keys, new_vals))
else:
new_map = {}
for x in reuse_weights: