text stringlengths 0 4.99k |
|---|
) |
return dataset.prefetch(auto) |
train_dataset = make_datasets(new_x_train, new_y_train, is_train=True) |
val_dataset = make_datasets(x_val, y_val) |
test_dataset = make_datasets(x_test, y_test) |
2021-10-17 03:43:59.588315: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:43:59.596532: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:43:59.597211: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:43:59.622016: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA |
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. |
2021-10-17 03:43:59.622853: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:43:59.623542: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:43:59.624174: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:44:00.067659: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:44:00.068334: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:44:00.068970: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero |
2021-10-17 03:44:00.069615: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 14684 MB memory: -> device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:04.0, compute capability: 7.0 |
ConvMixer utilities |
The following figure (taken from the original paper) depicts the ConvMixer model: |
ConvMixer is very similar to the MLP-Mixer, model with the following key differences: |
Instead of using fully-connected layers, it uses standard convolution layers. |
Instead of LayerNorm (which is typical for ViTs and MLP-Mixers), it uses BatchNorm. |
Two types of convolution layers are used in ConvMixer. (1): Depthwise convolutions, for mixing spatial locations of the images, (2): Pointwise convolutions (which follow the depthwise convolutions), for mixing channel-wise information across the patches. Another keypoint is the use of larger kernel sizes to allow a lar... |
def activation_block(x): |
x = layers.Activation(\"gelu\")(x) |
return layers.BatchNormalization()(x) |
def conv_stem(x, filters: int, patch_size: int): |
x = layers.Conv2D(filters, kernel_size=patch_size, strides=patch_size)(x) |
return activation_block(x) |
def conv_mixer_block(x, filters: int, kernel_size: int): |
# Depthwise convolution. |
x0 = x |
x = layers.DepthwiseConv2D(kernel_size=kernel_size, padding=\"same\")(x) |
x = layers.Add()([activation_block(x), x0]) # Residual. |
# Pointwise convolution. |
x = layers.Conv2D(filters, kernel_size=1)(x) |
x = activation_block(x) |
return x |
def get_conv_mixer_256_8( |
image_size=32, filters=256, depth=8, kernel_size=5, patch_size=2, num_classes=10 |
): |
\"\"\"ConvMixer-256/8: https://openreview.net/pdf?id=TVHS5Y4dNvM. |
The hyperparameter values are taken from the paper. |
\"\"\" |
inputs = keras.Input((image_size, image_size, 3)) |
x = layers.Rescaling(scale=1.0 / 255)(inputs) |
# Extract patch embeddings. |
x = conv_stem(x, filters, patch_size) |
# ConvMixer blocks. |
for _ in range(depth): |
x = conv_mixer_block(x, filters, kernel_size) |
# Classification block. |
x = layers.GlobalAvgPool2D()(x) |
outputs = layers.Dense(num_classes, activation=\"softmax\")(x) |
return keras.Model(inputs, outputs) |
The model used in this experiment is termed as ConvMixer-256/8 where 256 denotes the number of channels and 8 denotes the depth. The resulting model only has 0.8 million parameters. |
Model training and evaluation utility |
# Code reference: |
# https://keras.io/examples/vision/image_classification_with_vision_transformer/. |
def run_experiment(model): |
optimizer = tfa.optimizers.AdamW( |
learning_rate=learning_rate, weight_decay=weight_decay |
) |
model.compile( |
optimizer=optimizer, |
loss=\"sparse_categorical_crossentropy\", |
metrics=[\"accuracy\"], |
) |
checkpoint_filepath = \"/tmp/checkpoint\" |
checkpoint_callback = keras.callbacks.ModelCheckpoint( |
checkpoint_filepath, |
monitor=\"val_accuracy\", |
save_best_only=True, |
save_weights_only=True, |
) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.