我正在训练一个 keras 序列模型。我希望在训练没有进展时降低学习率。
我使用 ReduceLROnPlateau 回调。
在前 2 个 epoch 没有进展后,学习率按预期降低。但随后每 2 个 epoch 减少一次,导致训练停止进展。
那是keras错误吗?或者我以错误的方式使用该功能?
编码:
earlystopper = EarlyStopping(patience=8, verbose=1)
checkpointer = ModelCheckpoint(filepath = 'model_zero7.{epoch:02d}-{val_loss:.6f}.hdf5',
verbose=1,
save_best_only=True, save_weights_only = True)
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.2,
patience=2, min_lr=0.000001, verbose=1)
history_zero7 = model_zero.fit_generator(bach_gen_only1,
validation_data = (v_im, v_lb),
steps_per_epoch=25,epochs=100,
callbacks=[earlystopper, checkpointer, reduce_lr])
Run Code Online (Sandbox Code Playgroud)
输出:
Epoch 00006: val_loss did not improve from 0.68605
Epoch 7/100
25/25 [==============================] - 213s 9s/step - loss: 0.6873 - binary_crossentropy: 0.0797 - dice_coef_loss: -0.8224 - jaccard_distance_loss_flat: 0.2998 - val_loss: 0.6865 …Run Code Online (Sandbox Code Playgroud) 我需要沿 Z 轴翻转 3D 数组 A 形状 [m, n, k]。我需要平面 0 (A[0,:,:]) 变为 k-1,平面 1 变为 k-2 平面,依此类推。
我需要在许多数组上执行此操作,并且循环非常慢。
我试过:
C = numpy.rot90(A,2)
C = flipud(A)
C = A[::-1]
Run Code Online (Sandbox Code Playgroud)
我还尝试了 rol 和 reshape,但不是我需要的。
例如:A 是 (3, 2, 2)
A= np.array([[[ 1.01551435, -0.76494131],
[ 0.56853752 , 1.94491724]],
[[-0.97433012 , 2.08134198],
[-1.34997602 ,-0.33543117]],
[[ 0.54217072, -1.33470658],
[-0.50179028, -0.66593918]]])
Run Code Online (Sandbox Code Playgroud)
我需要将 Z 轴倒置重新排序:
[[ 0.54217072 -1.33470658]
[-0.50179028 -0.66593918]]
[[-0.7703279 0.02402204]
[-0.18006451 -0.37589744]]
[[ 1.01551435 -0.76494131]
[ 0.56853752 1.94491724]]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
我想以 4 精度打印浮点数。我使用 numpy ,我尝试过的 jupyter notebook:
%precision %.4g
%precision 2
np.set_printoptions(precision=2)
print(0.6776776)
Run Code Online (Sandbox Code Playgroud)
输出:
0.6776776
Run Code Online (Sandbox Code Playgroud)
任何想法有什么问题?
# Name Version
ipython 6.4.0
ipython_genutils 0.2.0
msgpack-python 0.5.6
python 3.6.5
python-dateutil 2.7.3
Run Code Online (Sandbox Code Playgroud) 我有大数据框,我需要有效地计算数据框行和给定值列表之间的相关性。例如:
dfa= DataFrame(np.zeros((1,4)) ,columns=['a','b','c','d'])
dfa.ix[0] = [2,6,8,12]
a b c d
2.0 6.0 8.0 12.0
dfb= DataFrame([[2,6,8,12],[1,3,4,6],[-1,-3,-4,-6]], columns=['a','b','c','d'])
a b c d
0 2 6 8 12
1 1 3 4 6
2 -1 -3 -4 -6
Run Code Online (Sandbox Code Playgroud)
我希望得到:
0 1
1 0.5
2 -0.5
Run Code Online (Sandbox Code Playgroud)
我尝试了很多版本,例如:
dfb.T.corrwith(dfa.T, axis=0)
Run Code Online (Sandbox Code Playgroud)
但我得到的是很多南的
我在miniconda中创建了python 3.6环境。Jupyter Notebook现在从右到左工作

我该如何解决?
已安装的软件包:
ipykernel 4.7.0 py36_0 conda-forge
ipython 6.2.1 py36_1 conda-forge
ipython_genutils 0.2.0 py36_0 conda-forge
jsonschema 2.5.1 py36_0 conda-forge
jupyter_client 5.2.1 py36_0 conda-forge
jupyter_core 4.4.0 py_0 conda-forge
notebook 5.2.2 py36_1 conda-forge
Run Code Online (Sandbox Code Playgroud)
笔记本元数据:
{
"celltoolbar": "Edit Metadata",
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.4",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
}
Run Code Online (Sandbox Code Playgroud) python ×4
numpy ×2
anaconda ×1
arrays ×1
correlation ×1
keras ×1
keras-2 ×1
pandas ×1
performance ×1
precision ×1
python-2.7 ×1