kerasify icon indicating copy to clipboard operation
kerasify copied to clipboard

Cannot create a VGG16 model (AssertionError: Unsupported layer type: InputLayer)

Open fraztto opened this issue 7 years ago • 2 comments

I'm currently trying to use Kerasify to make the code for a VGG16 network, but I get the following error:

AssertionError: Unsupported layer type: InputLayer

I'm using a simple VGG16 Model on top of a MLP

The model summary is:

Layer (type)                 Output Shape              Param #   

input_1 (InputLayer)         (None, 64, 64, 3)         0         

block1_conv1 (Conv2D)        (None, 64, 64, 64)        1792      

block1_conv2 (Conv2D)        (None, 64, 64, 64)        36928     

block1_pool (MaxPooling2D)   (None, 32, 32, 64)        0         

block2_conv1 (Conv2D)        (None, 32, 32, 128)       73856     

block2_conv2 (Conv2D)        (None, 32, 32, 128)       147584    

block2_pool (MaxPooling2D)   (None, 16, 16, 128)       0         

block3_conv1 (Conv2D)        (None, 16, 16, 256)       295168    

block3_conv2 (Conv2D)        (None, 16, 16, 256)       590080    

block3_conv3 (Conv2D)        (None, 16, 16, 256)       590080    

block3_pool (MaxPooling2D)   (None, 8, 8, 256)         0         

block4_conv1 (Conv2D)        (None, 8, 8, 512)         1180160   

block4_conv2 (Conv2D)        (None, 8, 8, 512)         2359808   

block4_conv3 (Conv2D)        (None, 8, 8, 512)         2359808   

block4_pool (MaxPooling2D)   (None, 4, 4, 512)         0         

block5_conv1 (Conv2D)        (None, 4, 4, 512)         2359808   

block5_conv2 (Conv2D)        (None, 4, 4, 512)         2359808   

block5_conv3 (Conv2D)        (None, 4, 4, 512)         2359808   

block5_pool (MaxPooling2D)   (None, 2, 2, 512)         0         

sequential_1 (Sequential)    (None, 1)                 524801    

Total params: 15,239,489
Trainable params: 15,239,489
Non-trainable params: 0

fraztto avatar Jun 02 '17 04:06 fraztto

i have the same problem

anguoyang avatar Jul 03 '17 02:07 anguoyang

You can ignore InputLayer in kerasify.py with sample code:

model_layers = [l for l in model.layers if type(l).__name__ not in ['Dropout','InputLayer']]

If you are using VGG16 with top, you have to add support for Softmax too. These should be done by add type and output code in kerasify.py, and implementation in keras_model.cc. sample code:

	case kSoftMax:
		{
			float sum = 0.0;
			for (size_t i = 0; i < out->data_.size(); i++) {
				out->data_[i] = std::exp(out->data_[i]);
				sum += out->data_[i];
			}
			for (size_t i = 0; i < out->data_.size(); i++) {
				out->data_[i] /= sum;
			}
		}
		break; 

hepesu avatar Aug 01 '17 17:08 hepesu