|
@@ -7,9 +7,10 @@ import numpy as np
|
|
|
|
|
|
from annotations import NAB_Annotations, CUB_Annotations
|
|
from annotations import NAB_Annotations, CUB_Annotations
|
|
from dataset import Dataset
|
|
from dataset import Dataset
|
|
-from dataset.utils import reveal_parts, \
|
|
|
|
- visible_part_locs, visible_crops, \
|
|
|
|
- uniform_part_locs, crops
|
|
|
|
|
|
+from dataset.utils import reveal_parts, uniform_parts, \
|
|
|
|
+ random_select, \
|
|
|
|
+ visible_part_locs, visible_crops
|
|
|
|
+
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
@@ -42,31 +43,34 @@ def main(args):
|
|
im, parts, label = data[i]
|
|
im, parts, label = data[i]
|
|
|
|
|
|
if args.uniform_parts:
|
|
if args.uniform_parts:
|
|
- idxs, xy = uniform_part_locs(im, ratio=args.ratio)
|
|
|
|
- else:
|
|
|
|
- idxs, xy = visible_part_locs(parts)
|
|
|
|
|
|
+ parts = uniform_parts(im, ratio=args.ratio)
|
|
|
|
+
|
|
|
|
+ idxs, xy = visible_part_locs(parts)
|
|
|
|
+ part_crops = visible_crops(im, parts, ratio=args.ratio)
|
|
|
|
|
|
logging.debug(label)
|
|
logging.debug(label)
|
|
logging.debug(idxs)
|
|
logging.debug(idxs)
|
|
|
|
+ logging.debug(xy)
|
|
|
|
|
|
fig1 = plt.figure(figsize=(16,9))
|
|
fig1 = plt.figure(figsize=(16,9))
|
|
ax = fig1.add_subplot(2,1,1)
|
|
ax = fig1.add_subplot(2,1,1)
|
|
ax.imshow(im)
|
|
ax.imshow(im)
|
|
|
|
+ ax.set_title("Visible Parts")
|
|
ax.scatter(*xy, marker="x", c=idxs)
|
|
ax.scatter(*xy, marker="x", c=idxs)
|
|
ax.axis("off")
|
|
ax.axis("off")
|
|
|
|
|
|
|
|
+ if args.rnd:
|
|
|
|
+ idxs, xy, part_crops = random_select(idxs, xy, part_crops)
|
|
|
|
+
|
|
ax = fig1.add_subplot(2,1,2)
|
|
ax = fig1.add_subplot(2,1,2)
|
|
|
|
+ ax.set_title("{}selected parts".format("randomly " if args.rnd else ""))
|
|
ax.imshow(reveal_parts(im, xy, ratio=args.ratio))
|
|
ax.imshow(reveal_parts(im, xy, ratio=args.ratio))
|
|
ax.scatter(*xy, marker="x", c=idxs)
|
|
ax.scatter(*xy, marker="x", c=idxs)
|
|
ax.axis("off")
|
|
ax.axis("off")
|
|
|
|
|
|
- if args.uniform_parts:
|
|
|
|
- part_crops = crops(im, xy, ratio=args.ratio)
|
|
|
|
- else:
|
|
|
|
- part_crops = visible_crops(im, parts, ratio=args.ratio)
|
|
|
|
-
|
|
|
|
fig2 = plt.figure(figsize=(16,9))
|
|
fig2 = plt.figure(figsize=(16,9))
|
|
- n_crops = len(part_crops)
|
|
|
|
|
|
+
|
|
|
|
+ n_crops = part_crops.shape[0]
|
|
rows = int(np.ceil(np.sqrt(n_crops)))
|
|
rows = int(np.ceil(np.sqrt(n_crops)))
|
|
cols = int(np.ceil(n_crops / rows))
|
|
cols = int(np.ceil(n_crops / rows))
|
|
|
|
|