Пример #1
0
    def __init__(self, labels=CRAFTED_LABELS):
        """
			Detects fish from the OverFeat network Localizer
			Reference:
			P Sermanet, D. Eigen, X. Zhang, M. Mathieu, R. Fergus, Y. LeCun. 
			OverFeat: Integrated Recognition, Localization, and Detection 
			using Convolutional Networks
			International Conference on Learning Representations (ICLR 2014), April 2014.
		"""
        self.localizer = OverfeatLocalizer(match_strings=labels, top_n=2)
Пример #2
0
# Show all the boxes being processed
axarr[1, 0].imshow(X / 255.)
axarr[1, 0].axis('off')
# Hard code box size to speed up processing
x_points = np.linspace(0, X.shape[1] - 231, 13)
y_points = np.linspace(0, X.shape[0] - 231, 10)
xx, yy = np.meshgrid(x_points, y_points)
for x, y in zip(xx.flat, yy.flat):
    axarr[1, 0].add_patch(Rectangle((x, y), 231, 231, fc='yellow', ec='black',
                          alpha=.4))

print("Starting localization")
# Get all points with sloth in the top 5 labels
sloth_label = "three-toed sloth, ai, Bradypus tridactylus"
clf = OverfeatLocalizer(match_strings=[sloth_label])
sloth_points = clf.predict(X)[0]
axarr[1, 1].imshow(X / 255.)
axarr[1, 1].axis('off')
axarr[1, 1].autoscale(enable=False)
axarr[1, 1].scatter(sloth_points[:, 0], sloth_points[:, 1], color='orange',
                    s=50)
print("Localization complete!")


def convert_gmm_to_box(gmm, color, alpha):
    midpoint = gmm.means_
    std = 3 * np.sqrt(clf.covars_)
    width = std[:, 0]
    height = std[:, 1]
    upper_left_point = (midpoint[:, 0] - width // 2,
# Show all the boxes being processed
axarr[0, 2].imshow(X)
axarr[0, 2].axis('off')
clf = OverfeatTransformer(force_reshape=False)
X_tf = clf.transform(X)
x_points = np.linspace(0, X.shape[1] - 231, X_tf[0].shape[3])
y_points = np.linspace(0, X.shape[0] - 231, X_tf[0].shape[2])
xx, yy = np.meshgrid(x_points, y_points)
for x, y in zip(xx.flat, yy.flat):
    axarr[0, 2].add_patch(
        Rectangle((x, y), 231, 231, fc='yellow', ec='black', alpha=.4))

# Get all points with sloth in the top 5 labels
sloth_label = "three-toed sloth, ai, Bradypus tridactylus"
clf = OverfeatLocalizer(match_strings=[sloth_label])
sloth_points = clf.predict(X)[0]
axarr[1, 0].imshow(X)
axarr[1, 0].axis('off')
axarr[1, 0].autoscale(enable=False)
axarr[1, 0].scatter(sloth_points[:, 0],
                    sloth_points[:, 1],
                    color='orange',
                    s=50)

# Final localization box
sloth_box = convert_points_to_box(sloth_points, 'orange', .6)
axarr[1, 1].imshow(X)
axarr[1, 1].autoscale(enable=False)
axarr[1, 1].add_patch(sloth_box)
axarr[1, 1].axis('off')