mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-08 07:39:33 +01:00
Summary: There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports: ```2to3 -f future -w caffe2``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033 Reviewed By: seemethere Differential Revision: D23808648 Pulled By: bugra fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
44 lines
1011 B
Python
44 lines
1011 B
Python
|
|
|
|
import numpy as np
|
|
from caffe2.python import core, workspace
|
|
from caffe2.quantization.server import dnnlowp_pybind11 # type: ignore[attr-defined]
|
|
|
|
|
|
net = core.Net("test_net")
|
|
|
|
X = np.array([[1, 2], [3, 4]]).astype(np.float32)
|
|
W = np.array([[5, 6], [7, 8]]).astype(np.float32)
|
|
b = np.array([0, 1]).astype(np.float32)
|
|
|
|
workspace.FeedBlob("X", X)
|
|
workspace.FeedBlob("W", W)
|
|
workspace.FeedBlob("b", b)
|
|
|
|
Y = net.FC(["X", "W", "b"], ["Y"])
|
|
|
|
dnnlowp_pybind11.ObserveMinMaxOfOutput("test_net.minmax", 1)
|
|
workspace.CreateNet(net)
|
|
workspace.RunNet(net)
|
|
print(workspace.FetchBlob("Y"))
|
|
|
|
workspace.ResetWorkspace()
|
|
|
|
workspace.FeedBlob("X", X)
|
|
workspace.FeedBlob("W", W)
|
|
workspace.FeedBlob("b", b)
|
|
|
|
dnnlowp_pybind11.ObserveHistogramOfOutput("test_net.hist", 1)
|
|
workspace.CreateNet(net)
|
|
workspace.RunNet(net)
|
|
|
|
|
|
workspace.FeedBlob("X", X)
|
|
workspace.FeedBlob("W", W)
|
|
workspace.FeedBlob("b", b)
|
|
|
|
dnnlowp_pybind11.AddOutputColumnMaxHistogramObserver(
|
|
net._net.name, "test_net._col_max_hist", ["Y"]
|
|
)
|
|
workspace.RunNet(net)
|