有一个实用程序function在Tensorflow中执行此操作。但是,我需要它在Pytorch中。我已经使用匹配Tensorflow的实现在Pytorch中成功地使用“相同”或“有效”填充实现了深度卷积。 using UnityEngine;
using Npgsql;
public class BancoDeDados : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
string connectionString =
"Server=Projeto E-Battle;" +
"Database=e-battle;" +
"User ID=postgres;" +
"Password=senha;";
// IDbConnection dbcon; ## CHANGE THIS TO
NpgsqlConnection dbcon;
dbcon = new NpgsqlConnection(connectionString);
dbcon.Open();
//IDbCommand dbcmd = dbcon.CreateCommand();## CHANGE THIS TO
NpgsqlCommand dbcmd = dbcon.CreateCommand();
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT id_tema, nome " +
"FROM temas";
dbcmd.CommandText = sql;
//IDataReader reader = dbcmd.ExecuteReader(); ## CHANGE THIS TO
NpgsqlDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string id_tema = (string) reader["id_tema"];
string nome = (string) reader["nome"];
System.Console.WriteLine("Name: " +
id_tema + " " + nome);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
我无法按如下方式计算匹配的梯度:
depthwise_conv2d_torch(input, stride, kernel, padding) == tf.nn.depthwise_conv2d(input, stride, kernel, padding)
我得到的def depthwise_conv2d_backprop_input_pt(depthwise_out, images):
return T.autograd.grad(outputs = depthwise_out, inputs = images, grad_outputs = T.ones_like(depthwise_out))
和depthwise_conv2d_backprop_input_pt
的值千差万别
我已经坚持了一段时间,甚至尝试使用Tensorflow的参考cpp实现来尝试实现此目标,但无济于事。