有没有办法输入抽象父类方法,以便知道子类方法返回自身,而不是抽象父类。
class Parent(ABC):
@abstractmethod
def method(self) -> [what to hint here]:
pass
class Child1(Parent)
def method(self):
pass
def other_method(self):
pass
class GrandChild1(Child1)
def other_method_2(self):
pass
Run Code Online (Sandbox Code Playgroud)
这更多是为了改进 PyCharm 或 VScode 的 python 插件等 IDE 的自动完成功能。
我正在尝试在训练后从模型中提取权重.这是一个玩具的例子
import tensorflow as tf
import numpy as np
X_ = tf.placeholder(tf.float64, [None, 5], name="Input")
Y_ = tf.placeholder(tf.float64, [None, 1], name="Output")
X = ...
Y = ...
with tf.name_scope("LogReg"):
pred = fully_connected(X_, 1, activation_fn=tf.nn.sigmoid)
loss = tf.losses.mean_squared_error(labels=Y_, predictions=pred)
training_ops = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(200):
sess.run(training_ops, feed_dict={
X_: X,
Y_: Y
})
if (i + 1) % 100 == 0:
print("Accuracy: ", sess.run(accuracy, feed_dict={
X_: X,
Y_: Y
}))
# Get weights of *pred* here …Run Code Online (Sandbox Code Playgroud)