<jupyter_start><jupyter_text>Disable GPU (if needed)<jupyter_code>import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""<jupyter_output><empty_output><jupyter_text>Minimal example - Keras API<jupyter_code>from tensorflow.keras.layers import Activation, Conv2D, Input
from tensorflow.keras.layers import AvgPool2D
from tensorflow.keras.models import Model
from receptivefield.image import get_default_image
from receptivefield.keras import KerasReceptiveField
import matplotlib.pyplot as plt

# define model function
def model_build_func(input_shape):
    act = 'linear' # see Remarks
    inp = Input(shape=input_shape, name='input_image')
    x = Conv2D(32, (7, 7), activation=act)(inp)
    x = Conv2D(32, (5, 5), activation=act)(x)
    x = AvgPool2D()(x)
    x = Conv2D(64, (5, 5), activation=act, name='feature_grid')(x)
    x = AvgPool2D()(x)
    model = Model(inp, x)
    return model

shape = [64, 64, 3]
# compute receptive field
rf = KerasReceptiveField(model_build_func)
rf_params = rf.compute(shape, 'input_image', ['feature_grid'])

# debug receptive field
rf.plot_rf_grids(get_default_image(shape, name='doge'), figsize=(10, 10))
print(rf_params)
rf.feature_maps_desc
rf.num_feature_maps
rf.input_shape
rf.output_shapes<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1205837173579109, 'fraction_numerical': 0.021505376344086023, 'mean_word_length': 6.488505747126437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '521193', 'license': 'Apache-2.0', 'n_tokens_mistral': 505, 'n_tokens_neox': 477, 'n_words': 99, 'path': 'easy-receptive-fields-pytorch/receptivefield/notebooks/minimal_example_with_keras_API.ipynb', 'repo_name': 'Swinsie/cv-rep-fork', 'size': '1302'}