关于in_channel,out_chanels和过滤器 过滤器与out_channels相同.在Keras中,in_channels是从上一层的形状或input_shape(在第一层的情况下)自动推断出来的.Keras and PyTorch use different arguments for padding: Keras requires a string to be input, while PyTorch works with numbers. What is the difference, and how can one be translated into another (what code gets the equivalent result in either framework)?PyTorch also takes the args in_channels, out_chanels while keras only takes an argument called filters. What does 'filters' mean? 解决方案 Regarding padding,Keras => 'valid' - no padding; 'same' - input is padded so that the output shape is same as input shapePytorch => you explicitly specify the paddingValid padding>>> model = keras.Sequential()>>> model.add(keras.layers.Conv2D(filters=10, kernel_size=3, padding='valid', input_shape=(28,28,3)))>>> model.layers[0].output_shape(None, 26, 26, 10)>>> x = torch.randn((1,3,28,28))>>> conv = torch.nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3)>>> conv(x).shapetorch.Size([1, 10, 26, 26])Same padding>>> model = keras.Sequential()>>> model.add(keras.layers.Conv2D(filters=10, kernel_size=3, padding='same', input_shape=(28,28,3)))>>> model.layers[0].output_shape(None, 28, 28, 10)>>> x = torch.randn((1,3,28,28))>>> conv = torch.nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3, padding=1)>>> conv(x).shapetorch.Size([1, 10, 28, 28])W - Input Width, F - Filter(or kernel) size, P - padding, S - Stride, Wout - Output widthWout = ((W−F+2P)/S)+1Similarly for Height. With this formula, you can calculate the amount of padding required to retain the input width or height in the output.http://cs231n.github.io/convolutional-networks/Regarding in_channels, out_chanels and filters,filters is the same as out_channels. In Keras, the in_channels is automatically inferred from the previous layer shape or input_shape(in case of first layer). 这篇关于将Keras(Tensorflow)卷积神经网络转换为PyTorch卷积网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-12 02:45