input: Write a function to construct a machine learning model in Python that can distinguish between cats and dogs. The function should take a dataset path as input, build the model, compile it, and fit it to the dataset. If the input dataset path is valid and the model is successfully constructed and trained, return True. If there are any errors during the process, return False. Return False if the dataset path is incorrect or the dataset does not contain images of cats and dogs.
  assert construct_cat_dog_model('/valid/path/to/dataset')==True
  assert construct_cat_dog_model('/invalid/path/to/dataset')==False
  assert construct_cat_dog_model('')==False
output: def construct_cat_dog_model(dataset_path):
      try:
          from tensorflow.keras.preprocessing.image import ImageDataGenerator
          from tensorflow.keras.models import Sequential
          from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
          from tensorflow.keras.optimizers import Adam
          import os
  
          if not os.path.exists(dataset_path):
              return False
  
          train_datagen = ImageDataGenerator(rescale=1./255)
          train_generator = train_datagen.flow_from_directory(
              dataset_path,
              target_size=(150, 150),
              batch_size=32,
              class_mode='binary'
          )
  
          if train_generator.num_classes != 2:
              return False
  
          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'])
          model.fit(train_generator, epochs=1)
  
          return True
      except:
          return False