Skip to content

Commit

Permalink
Convert .pyre_configuration.local to fast by default architecture] [b…
Browse files Browse the repository at this point in the history
…atch:44/100] [shard:2/N] [A]

Reviewed By: MaggieMoss

Differential Revision: D63644535

fbshipit-source-id: f4118078d10c24b1fd5c400659c5f3c70ae2c781
  • Loading branch information
generatedunixname89002005307016 authored and facebook-github-bot committed Sep 30, 2024
1 parent d1727b0 commit 7514c21
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 7 deletions.
2 changes: 2 additions & 0 deletions opensfm/actions/export_colmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ def array_to_blob(array) -> bytes:
if IS_PYTHON3:
return array.tobytes()
else:
# pyre-fixme[16]: Module `numpy` has no attribute `getbuffer`.
return np.getbuffer(array)


def blob_to_array(blob, dtype, shape: Tuple[int] = (-1,)):
if IS_PYTHON3:
# pyre-fixme[20]: Argument `sep` expected.
return np.fromstring(blob, dtype=dtype).reshape(*shape)
else:
return np.frombuffer(blob, dtype=dtype).reshape(*shape)
Expand Down
2 changes: 2 additions & 0 deletions opensfm/actions/export_geocoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def _transform_dense_point_cloud(
fout.write(line)
else:
x, y, z, nx, ny, nz, red, green, blue = line.split()
# pyre-fixme[6]: For 2nd argument expected `Union[Sequence[Sequen...
x, y, z = np.dot(A, map(float, [x, y, z])) + b
# pyre-fixme[6]: For 2nd argument expected `Union[Sequence[Sequen...
nx, ny, nz = np.dot(A, map(float, [nx, ny, nz]))
fout.write(
"{} {} {} {} {} {} {} {} {}\n".format(
Expand Down
4 changes: 4 additions & 0 deletions opensfm/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ def compute_orientation_prior_similarity(
max_scale = 1000
current_scale = np.linalg.norm(b)
if two_shots and current_scale > max_scale:
# pyre-fixme[58]: `/` is not supported for operand types `int` and
# `floating[typing.Any]`.
b = max_scale * b / current_scale
# pyre-fixme[58]: `/` is not supported for operand types `int` and
# `floating[typing.Any]`.
s = max_scale / current_scale
else:
try:
Expand Down
2 changes: 2 additions & 0 deletions opensfm/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def load_words(self, image: str) -> np.ndarray:

def save_words(self, image: str, words: np.ndarray) -> None:
with self.io_handler.open(self._words_file(image), "wb") as f:
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsWrite[bytes],
# PathLike[str], str]` but got `IO[typing.Any]`.
np.savez_compressed(f, words=words.astype(np.uint16))

def _matches_path(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions opensfm/feature_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def _add_segmentation_in_descriptor(
return features

desc_augmented = np.concatenate(
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[ty...
(
features.descriptors,
(np.array([segmentation]).T).astype(np.float32),
Expand Down
2 changes: 2 additions & 0 deletions opensfm/features_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def bake_segmentation(
new_width=new_width,
new_height=new_height,
).astype(int)
# pyre-fixme[6]: For 2nd argument expected `None` but got
# `ndarray[typing.Any, typing.Any]`.
panoptic_data[i] = p_data[ps[:, 1], ps[:, 0]]
return tuple(panoptic_data)

Expand Down
11 changes: 10 additions & 1 deletion opensfm/multiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def ransac(kernel: Any, threshold: float) -> TRansacSolution:
max_iterations, ransac_max_iterations(kernel, best_inliers, 0.01)
)
i += 1
# pyre-fixme[7]: Expected `Tuple[ndarray[typing.Any, typing.Any],
# ndarray[typing.Any, typing.Any], float]` but got `Tuple[typing.Any,
# Union[List[typing.Any], ndarray[typing.Any, dtype[typing.Any]]], typing.Any]`.
return best_model, best_inliers, best_error


Expand Down Expand Up @@ -211,6 +214,8 @@ def num_samples(self) -> int:
def fit(self, samples: np.ndarray) -> List[float]:
x = self.x[samples[0]]
y = self.y[samples[0]]
# pyre-fixme[7]: Expected `List[float]` but got `List[ndarray[typing.Any,
# dtype[typing.Any]]]`.
return [y / x]

def evaluate(self, model: np.ndarray) -> np.ndarray:
Expand Down Expand Up @@ -416,6 +421,9 @@ def fit_similarity_transform(
errors = np.sqrt(np.sum((p2h.T - np.dot(best_T, p1h.T)) ** 2, axis=0))
best_inliers = np.argwhere(errors < threshold)[:, 0]

# pyre-fixme[7]: Expected `Tuple[ndarray[typing.Any, typing.Any],
# ndarray[typing.Any, typing.Any]]` but got `Tuple[ndarray[typing.Any,
# typing.Any], Union[List[typing.Any], ndarray[typing.Any, dtype[typing.Any]]]]`.
return best_T, best_inliers


Expand Down Expand Up @@ -453,7 +461,9 @@ def focal_from_homography(H: np.ndarray) -> np.ndarray:
def R_from_homography(
H: np.ndarray, f1: np.ndarray, f2: np.ndarray
) -> Optional[np.ndarray]:
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[typing.Any...
K1 = np.diag([f1, f1, 1])
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[typing.Any...
K2 = np.diag([f2, f2, 1])
K2inv = np.linalg.inv(K2)
R = K2inv.dot(H).dot(K1)
Expand All @@ -464,7 +474,6 @@ def R_from_homography(
def project_to_rotation_matrix(A: np.ndarray) -> Optional[np.ndarray]:
try:
u, d, vt = np.linalg.svd(A)
# pyre-fixme[16]: Module `linalg` has no attribute `LinAlgError`.
except np.linalg.linalg.LinAlgError:
return None
return u.dot(vt)
Expand Down
2 changes: 2 additions & 0 deletions opensfm/pairs_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def construct_pairs(
order = np.argsort(distances)
if enforce_other_cameras:
pairs.update(
# pyre-fixme[6]: For 4th argument expected `List[int]` but got
# `ndarray[typing.Any, dtype[typing.Any]]`.
pairs_from_neighbors(im, exifs, distances, order, other, max_neighbors)
)
else:
Expand Down
7 changes: 7 additions & 0 deletions opensfm/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def _two_view_reconstruction_inliers(
) -> List[int]:
"""Returns indices of matches that can be triangulated."""
ok = matching.compute_inliers_bearings(b1, b2, R, t, threshold)
# pyre-fixme[7]: Expected `List[int]` but got `ndarray[typing.Any,
# dtype[typing.Any]]`.
return np.nonzero(ok)[0]


Expand Down Expand Up @@ -318,6 +320,7 @@ def two_view_reconstruction_plane_based(
inliers = _two_view_reconstruction_inliers(b1, b2, R.T, -R.T.dot(t), threshold)
motion_inliers.append(inliers)

# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[typing.Any...
best = np.argmax(map(len, motion_inliers))
R, t, n, d = motions[best]
inliers = motion_inliers[best]
Expand Down Expand Up @@ -370,6 +373,8 @@ def _two_view_rotation_inliers(
) -> List[int]:
br2 = R.dot(b2.T).T
ok = np.linalg.norm(br2 - b1, axis=1) < threshold
# pyre-fixme[7]: Expected `List[int]` but got `ndarray[typing.Any,
# dtype[typing.Any]]`.
return np.nonzero(ok)[0]


Expand Down Expand Up @@ -1048,6 +1053,8 @@ def triangulate_dlt(

if len(Rts) >= 2:
e, X = pygeometry.triangulate_bearings_dlt(
# pyre-fixme[6]: For 1st argument expected `List[ndarray[typing.Any,
# typing.Any]]` but got `ndarray[typing.Any, dtype[typing.Any]]`.
np.asarray(Rts),
np.asarray(bs),
reproj_threshold,
Expand Down
2 changes: 2 additions & 0 deletions opensfm/synthetic_data/synthetic_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def _gps_dop(shot: pymap.Shot) -> float:
):
pose = rig_instance.pose.get_origin()
if previous_pose is not None:
# pyre-fixme[58]: `+` is not supported for operand types `int` and
# `floating[typing.Any]`.
previous_time += np.linalg.norm(pose - previous_pose) / speed_ms
previous_pose = pose
for shot_id in rig_instance.shots:
Expand Down
6 changes: 6 additions & 0 deletions opensfm/synthetic_data/synthetic_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ def __init__(
def combine(self, other_scene: "SyntheticStreetScene") -> "SyntheticStreetScene":
combined_scene = SyntheticStreetScene(None)
combined_scene.wall_points = np.concatenate(
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[ty...
(self.wall_points, other_scene.wall_points)
)
combined_scene.floor_points = np.concatenate(
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[ty...
(self.floor_points, other_scene.floor_points)
)
combined_scene.cameras = self.cameras + other_scene.cameras
Expand Down Expand Up @@ -400,7 +402,11 @@ def get_reconstruction(self) -> types.Reconstruction:
wall_color = [10, 90, 130]

return sg.create_reconstruction(
# pyre-fixme[6]: For 1st argument expected `List[ndarray[typing.Any,
# typing.Any]]` but got `ndarray[typing.Any, dtype[typing.Any]]`.
points=np.asarray([self.floor_points, self.wall_points], dtype=object),
# pyre-fixme[6]: For 2nd argument expected `List[ndarray[typing.Any,
# typing.Any]]` but got `ndarray[typing.Any, dtype[typing.Any]]`.
colors=np.asarray([floor_color, wall_color]),
cameras=self.cameras,
shot_ids=self.shot_ids,
Expand Down
5 changes: 0 additions & 5 deletions opensfm/test/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,13 @@ def test_bundle_projection_fixed_internals(scene_synthetic) -> None:
color = g_obs["feature_color"]
pt = g_obs["feature"]
obs = pymap.Observation(
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
pt[0],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
pt[1],
# pyre-fixme[6]: For 3rd argument expected `float` but got
# `Dict[str, typing.Any]`.
g_obs["feature_scale"],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[0],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[1],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[2],
# pyre-fixme[6]: For 7th argument expected `int` but got
# `Dict[str, typing.Any]`.
Expand Down
2 changes: 2 additions & 0 deletions opensfm/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_dataset_load_features_sift(tmpdir) -> None:
after = data.load_features(image)
assert after
assert np.allclose(points, after.points)
# pyre-fixme[6]: For 2nd argument expected `Union[_SupportsArray[dtype[typing.Any...
assert np.allclose(descriptors, after.descriptors)
assert np.allclose(colors, after.colors)
semantic = after.semantic
Expand All @@ -34,4 +35,5 @@ def test_dataset_load_features_sift(tmpdir) -> None:
segmentations,
semantic.segmentation,
)
# pyre-fixme[6]: For 2nd argument expected `Union[_SupportsArray[dtype[typing.Any...
assert np.allclose(instances, semantic.instances)
1 change: 0 additions & 1 deletion opensfm/test/test_multiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_motion_from_plane_homography() -> None:
scale = 2 * np.random.rand() - 1
H = scale * (d * R - np.outer(t, n))

# pyre-fixme[6]: For 1st argument expected `ndarray` but got `int`.
motions = multiview.motion_from_plane_homography(H)
assert motions is not None
goodness = []
Expand Down
1 change: 1 addition & 0 deletions opensfm/test/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_track_triangulator_spherical() -> None:


def unit_vector(x: object) -> np.ndarray:
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[typing.Any...
return np.array(x) / np.linalg.norm(x)


Expand Down
4 changes: 4 additions & 0 deletions opensfm/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def create_tracks_manager(
instances[image][featureid] if image in instances else NO_VALUE,
)
obs = pymap.Observation(
# pyre-fixme[6]: For 8th argument expected `int` but got
# `Union[ndarray[typing.Any, typing.Any], int]`.
# pyre-fixme[6]: For 9th argument expected `int` but got
# `Union[ndarray[typing.Any, typing.Any], int]`.
x, y, s, int(r), int(g), int(b), featureid, segmentation, instance
)
tracks_manager.add_observation(image, str(track_id), obs)
Expand Down
10 changes: 10 additions & 0 deletions opensfm/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def scale_matrix(
"""
if direction is None:
# uniform scaling
# pyre-fixme[6]: For 1st argument expected `Union[_SupportsArray[dtype[typing...
M = numpy.diag([factor, factor, factor, 1.0])
if origin is not None:
M[:3, 3] = origin[:3]
Expand Down Expand Up @@ -466,6 +467,10 @@ def scale_from_matrix(
raise ValueError("no eigenvector corresponding to eigenvalue 1")
origin = numpy.real(V[:, i[-1]]).squeeze()
origin /= origin[3]
# pyre-fixme[7]: Expected `Tuple[ndarray[typing.Any, typing.Any],
# ndarray[typing.Any, typing.Any], ndarray[typing.Any, typing.Any]]` but got
# `Tuple[typing.Any, ndarray[typing.Any, dtype[typing.Any]],
# Optional[ndarray[typing.Any, dtype[typing.Any]]]]`.
return factor, origin, direction


Expand Down Expand Up @@ -1663,10 +1668,14 @@ def vector_norm(
data *= data
out = numpy.atleast_1d(numpy.sum(data, axis=axis))
numpy.sqrt(out, out)
# pyre-fixme[7]: Expected `float` but got `ndarray[typing.Any,
# dtype[typing.Any]]`.
return out
else:
data *= data
numpy.sum(data, axis=axis, out=out)
# pyre-fixme[7]: Expected `float` but got `ndarray[typing.Any,
# dtype[typing.Any]]`.
return numpy.sqrt(out, out)


Expand Down Expand Up @@ -1832,6 +1841,7 @@ def is_same_transform(matrix0: numpy.ndarray, matrix1: numpy.ndarray) -> numpy.n
matrix0 /= matrix0[3, 3]
matrix1 = numpy.array(matrix1, dtype=numpy.float64, copy=True)
matrix1 /= matrix1[3, 3]
# pyre-fixme[7]: Expected `ndarray[typing.Any, typing.Any]` but got `bool`.
return numpy.allclose(matrix0, matrix1)


Expand Down

0 comments on commit 7514c21

Please sign in to comment.