input: Write a function to collate a machine learning model in Python that distinguishes between cats and dogs. The function should take a dataset path as input and return the compiled model. If the dataset path is invalid, the function should return None.
  assert cat_dog_classifier('/valid/path/to/dataset').compile().loss == 'binary_crossentropy'
  assert cat_dog_classifier('/invalid/path/to/dataset') == None
output: def cat_dog_classifier(dataset_path):
      try:
          from tensorflow.keras.models import Sequential
          from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
          from tensorflow.keras.preprocessing.image import ImageDataGenerator
          
          datagen = ImageDataGenerator(rescale=1./255)
          train_generator = datagen.flow_from_directory(
              dataset_path,
              target_size=(150, 150),
              batch_size=32,
              class_mode='binary'
          )
          
          model = Sequential([
              Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
              MaxPooling2D(2, 2),
              Conv2D(64, (3, 3), activation='relu'),
              MaxPooling2D(2, 2),
              Conv2D(128, (3, 3), activation='relu'),
              MaxPooling2D(2, 2),
              Flatten(),
              Dense(512, activation='relu'),
              Dense(1, activation='sigmoid')
          ])
          
          model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
          return model
      except:
          return None