我需要提供model1的输出作为model2的输入。
A=keras.layers.Input(batch_shape=(3,500,500,3))
B=keras.layers.Conv2D(filters=3, kernel_size=3)(A)
model1=keras.models.Model(A,B)
C=keras.layers.Conv2D(filters=3, kernel_size=3)(B)
model2=keras.applications.vgg19.VGG19(input_tensor=B, weights='imagenet', include_top=False, pooling='avg')
#Error: You are trying to load a weight file containing 16 layers into a model with 17 layers.
正如错误消息所示,keras无法正确实现vgg网络。
vgg19网包含23层(不含顶部)。但如果输入张量是另一个模型的输出,则层数会发生变化。
vgg19_normal=keras.applications.vgg19.VGG19(input_tensor=A, weights=None, include_top=False, pooling='avg')
len(vgg19_normal.layers)
#23
vgg19_abnormal=keras.applications.vgg19.VGG19(input_tensor=B, weights=None, include_top=False, pooling='avg')
#input tensor B is the output of model1
len(vgg19_abnormal.layers)
#24
所以keras抱怨层数不相等。
答案 0 :(得分:0)
我仍有一些疑问,例如我不明白 ngOnInit(): void {
const that = this;
that.dtOptions = {
pagingType: 'full_numbers',
'lengthMenu': [[10, 25, 50, -1], [10, 25, 50, 'All']],
responsive: true,
search: '_INPUT_',
searchPlaceholder: 'Search records',
pageLength: 2,
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<any[]>(
'api/prodotti/prodotti_executing/',
dataTablesParameters, {
}
).subscribe(resp => {
that.prodotti = resp;
callback({
recordsTotal: resp.length,
data: []
});
});
},
//columns: [{ data: 'id' }, { data: 'firstName' }, { data: 'lastName' }]
};
}
ngAfterViewInit() {
const table = $('#datatables').DataTable();
// Edit record
table.on( 'click', '.edit', function () {
const $tr = $(this).closest('tr');
console.log(table);
const data = table.row($tr).data();
alert( 'You press on Row: ' + data[0] + ' ' + data[1] + ' ' + data[2] + '\'s row.' );
} );
// Delete a record
table.on( 'click', '.remove', function (e: any) {
const $tr = $(this).closest('tr');
table.row($tr).remove().draw();
e.preventDefault();
} );
的用途。无论如何,这是我目前的想法:
C
A=keras.layers.Input(batch_shape=(3,500,500,3))
B=keras.layers.Conv2D(filters=3, kernel_size=3)(A)
model1=keras.models.Model(A,B)
C=keras.layers.Conv2D(filters=3, kernel_size=3)(B)
vgg19=keras.applications.vgg19.VGG19(weights='imagenet', include_top=False, pooling='avg')(model1.output)
model2=keras.models.Model(inputs=A, outputs=vgg19)
的结果拓扑是
要制作此图片,我使用了keras.utils.plot_model。