我正在尝试遵循Deep Autoencoder Keras 示例.我得到了一个维度不匹配异常,但对于我的生活,我无法弄清楚为什么.当我只使用一个编码维度时它可以工作,但是当我堆叠它们时却不行.
例外:输入0与图层dense_18不兼容:
expected shape =(None,128),found shape =(None,32)*
错误就行了 decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))
from keras.layers import Dense,Input
from keras.models import Model
import numpy as np
# this is the size of the encoded representations
encoding_dim = 32
#NPUT LAYER
input_img = Input(shape=(784,))
#ENCODE LAYER
# "encoded" is the encoded representation of the input
encoded = Dense(encoding_dim*4, activation='relu')(input_img)
encoded = Dense(encoding_dim*2, activation='relu')(encoded)
encoded = Dense(encoding_dim, activation='relu')(encoded)
#DECODED LAYER
# "decoded" is the lossy reconstruction of the input
decoded …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Pandas中的多索引数据框创建一个自举样本.下面是一些生成我需要的数据的代码.
from itertools import product
import pandas as pd
import numpy as np
df = pd.DataFrame({'group1': [1, 1, 1, 2, 2, 3],
'group2': [13, 18, 20, 77, 109, 123],
'value1': [1.1, 2, 3, 4, 5, 6],
'value2': [7.1, 8, 9, 10, 11, 12]
})
df = df.set_index(['group1', 'group2'])
print df
Run Code Online (Sandbox Code Playgroud)
df数据框如下所示:
value1 value2
group1 group2
1 13 1.1 7.1
18 2.0 8.0
20 3.0 9.0
2 77 4.0 10.0
109 5.0 11.0
3 123 6.0 12.0
Run Code Online (Sandbox Code Playgroud)
我想从第一个索引中获取一个随机样本.例如,假设随机值np.random.randint(3,size=3)产生[3,2,2].我希望结果数据框看起来像:
value1 …Run Code Online (Sandbox Code Playgroud)