我是神经网络新手。我想在 TensorFlow 中制作一个自定义损失函数,但我需要获取权重向量,所以我这样做了:
def my_loss(weights):
def custom_loss(y, y_pred):
return weights*(y - y_pred)
return custom_loss
model.compile(optimizer='adam', loss=my_loss(weights), metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=None, validation_data=(x_test, y_test), epochs=100)
Run Code Online (Sandbox Code Playgroud)
当我启动它时,我收到此错误:
InvalidArgumentError: Incompatible shapes: [50000,10] vs. [32,10]
Run Code Online (Sandbox Code Playgroud)
形状是:
print(weights.shape)
print(y_train.shape)
Run Code Online (Sandbox Code Playgroud)
(50000, 10)
(50000, 10)
Run Code Online (Sandbox Code Playgroud)
所以我认为这是批次的问题,我没有很强的TensorFlow背景,所以我尝试使用全局变量以简单的方式解决
batch_index = 0
Run Code Online (Sandbox Code Playgroud)
然后在自定义回调中将其更新到“on_batch_begin”挂钩中。但这没有用,而且是一个糟糕的解决方案。那么,如何才能得到对应y的权重的精确部分呢?我有办法获取自定义损失中的当前批次索引吗?预先感谢您的帮助
我正在尝试使用PhpStorm和artisan服务器使用Laravel构建RESTful API,但是当我尝试使用Rest Client测试时,出现以下错误:

现在,我只编写GET方法,并在浏览器中接收到正确的输出,其地址为 http://localhost:8000/users
这是我的代码:
routes.php
Route::resource('users','UserController');
Run Code Online (Sandbox Code Playgroud)
UserController.php
public function index()
{
return \Response::json(User::all());
}
Run Code Online (Sandbox Code Playgroud)
我也尝试在请求窗口中添加json
