
"""simple docstring"""


import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
      from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder



def 	lowerCamelCase__			(							UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_=None		,      UpperCAmelCase_=None		,      UpperCAmelCase_=None		,      UpperCAmelCase_=None		,      UpperCAmelCase_=None		,      )->							List[Any]:







       """simple docstring"""
       if attention_mask is None:
              UpperCamelCase					 =		input_ids.ne(config.pad_token_id				)
       if decoder_attention_mask is None:
              UpperCamelCase					 =		decoder_input_ids.ne(config.pad_token_id				)
       if head_mask is None:
              UpperCamelCase					 =		torch.ones(config.encoder_layers		,      config.encoder_attention_heads		,      device=UpperCAmelCase_				)
       if decoder_head_mask is None:
              UpperCamelCase					 =		torch.ones(config.decoder_layers		,      config.decoder_attention_heads		,      device=UpperCAmelCase_				)
       if cross_attn_head_mask is None:
              UpperCamelCase					 =		torch.ones(config.decoder_layers		,      config.decoder_attention_heads		,      device=UpperCAmelCase_				)
       return {
           "input_ids": input_ids,
           "decoder_input_ids": decoder_input_ids,
           "attention_mask": attention_mask,
           "decoder_attention_mask": attention_mask,
           "head_mask": head_mask,
           "decoder_head_mask": decoder_head_mask,
           "cross_attn_head_mask": cross_attn_head_mask,
       }



class   __a  :






       def __init__(  self :							int       ,      UpperCAmelCase_ :							Dict       ,      UpperCAmelCase_ :							List[Any]=13       ,      UpperCAmelCase_ :							List[str]=7       ,      UpperCAmelCase_ :							str=True       ,      UpperCAmelCase_ :							Optional[int]=False       ,      UpperCAmelCase_ :							Union[str, Any]=99       ,      UpperCAmelCase_ :							Union[str, Any]=16       ,      UpperCAmelCase_ :							List[str]=2       ,      UpperCAmelCase_ :							str=4       ,      UpperCAmelCase_ :							Union[str, Any]=4       ,      UpperCAmelCase_ :							List[str]="relu"       ,      UpperCAmelCase_ :							List[str]=0.1       ,      UpperCAmelCase_ :							Dict=0.1       ,      UpperCAmelCase_ :							Optional[Any]=0.0       ,      UpperCAmelCase_ :							str=0.0       ,      UpperCAmelCase_ :							str=20       ,      UpperCAmelCase_ :							Optional[int]=2       ,      UpperCAmelCase_ :							List[str]=1       ,      UpperCAmelCase_ :							int=0       ,      )->  Optional[int]:







              """simple docstring"""
              UpperCamelCase					 =		parent
              UpperCamelCase					 =		batch_size
              UpperCamelCase					 =		seq_length
              UpperCamelCase					 =		is_training
              UpperCamelCase					 =		use_labels
              UpperCamelCase					 =		vocab_size
              UpperCamelCase					 =		hidden_size
              UpperCamelCase					 =		num_hidden_layers
              UpperCamelCase					 =		num_attention_heads
              UpperCamelCase					 =		intermediate_size
              UpperCamelCase					 =		hidden_act
              UpperCamelCase					 =		hidden_dropout_prob
              UpperCamelCase					 =		attention_probs_dropout_prob
              UpperCamelCase					 =		encoder_layerdrop
              UpperCamelCase					 =		decoder_layerdrop
              UpperCamelCase					 =		max_position_embeddings
              UpperCamelCase					 =		eos_token_id
              UpperCamelCase					 =		pad_token_id
              UpperCamelCase					 =		bos_token_id






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict			)->  Any:







              """simple docstring"""
              UpperCamelCase					 =		ids_tensor([self.batch_size, self.seq_length]       ,      self.vocab_size			)
              UpperCamelCase					 =		self.eos_token_id  # Eos Token
              UpperCamelCase					 =		ids_tensor([self.batch_size, self.seq_length]       ,      self.vocab_size			)

              # we need to clamp the input ids here to avoid having pad token in between
              # this is because for M2M100 the position_ids are prepared such that
              # all pad tokens have pos id = 2 and rest are between 2..seq_length
              # and the seq_length here is seq_length - num_pad_tokens
              # but when using past, there is no way of knowing if the past input ids had
              # pad tokens in them, which results in incorrect seq_lenth and which in turn results in
              # position_ids being off by num_pad_tokens in past input
              UpperCamelCase					 =		input_ids.clamp(self.pad_token_id + 1			)
              UpperCamelCase					 =		decoder_input_ids.clamp(self.pad_token_id + 1			)

              UpperCamelCase					 =		self.get_config()
              UpperCamelCase					 =		prepare_mam_aaa_inputs_dict(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_			)
              return config, inputs_dict






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[int]			)->  Optional[Any]:







              """simple docstring"""
              return MaMaaaConfig(
                  vocab_size=self.vocab_size       ,      d_model=self.hidden_size       ,      encoder_layers=self.num_hidden_layers       ,      decoder_layers=self.num_hidden_layers       ,      encoder_attention_heads=self.num_attention_heads       ,      decoder_attention_heads=self.num_attention_heads       ,      encoder_ffn_dim=self.intermediate_size       ,      decoder_ffn_dim=self.intermediate_size       ,      dropout=self.hidden_dropout_prob       ,      attention_dropout=self.attention_probs_dropout_prob       ,      encoder_layerdrop=self.encoder_layerdrop       ,      decoder_layerdrop=self.decoder_layerdrop       ,      max_position_embeddings=self.max_position_embeddings       ,      eos_token_id=self.eos_token_id       ,      bos_token_id=self.bos_token_id       ,      pad_token_id=self.pad_token_id       ,      )






       def 	_SCREAMING_SNAKE_CASE       (  self :							int			)->  Any:







              """simple docstring"""
              UpperCamelCase ,       UpperCamelCase					 =		self.prepare_config_and_inputs()
              return config, inputs_dict






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict       ,      UpperCAmelCase_ :							List[Any]       ,      UpperCAmelCase_ :							Tuple			)->  List[str]:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaModel(config=UpperCAmelCase_			).get_decoder().to(UpperCAmelCase_			).eval()
              UpperCamelCase					 =		inputs_dict["input_ids"]
              UpperCamelCase					 =		inputs_dict["attention_mask"]
              UpperCamelCase					 =		inputs_dict["head_mask"]

              # first forward pass
              UpperCamelCase					 =		model(UpperCAmelCase_       ,      attention_mask=UpperCAmelCase_       ,      head_mask=UpperCAmelCase_       ,      use_cache=UpperCAmelCase_			)

              UpperCamelCase ,       UpperCamelCase					 =		outputs.to_tuple()

              # create hypothetical multiple next token and extent to next_input_ids
              UpperCamelCase					 =		ids_tensor((self.batch_size, 3)       ,      config.vocab_size			)
              UpperCamelCase					 =		ids_tensor((self.batch_size, 3)       ,      2			)

              # append to next input_ids and
              UpperCamelCase					 =		torch.cat([input_ids, next_tokens]       ,      dim=-1			)
              UpperCamelCase					 =		torch.cat([attention_mask, next_attn_mask]       ,      dim=-1			)

              UpperCamelCase					 =		model(UpperCAmelCase_       ,      attention_mask=UpperCAmelCase_			)["last_hidden_state"]
              UpperCamelCase					 =		model(UpperCAmelCase_       ,      attention_mask=UpperCAmelCase_       ,      past_key_values=UpperCAmelCase_			)[
                  "last_hidden_state"
              ]

              # select random slice
              UpperCamelCase					 =		ids_tensor((1,)       ,      output_from_past.shape[-1]			).item()
              UpperCamelCase					 =		output_from_no_past[:, -3:, random_slice_idx].detach()
              UpperCamelCase					 =		output_from_past[:, :, random_slice_idx].detach()

              self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]			)

              # test that outputs are equal for slice
              self.parent.assertTrue(torch.allclose(UpperCAmelCase_       ,      UpperCAmelCase_       ,      atol=1e-2			)			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict       ,      UpperCAmelCase_ :							Union[str, Any]       ,      UpperCAmelCase_ :							List[Any]			)->  str:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaModel(config=UpperCAmelCase_			).to(UpperCAmelCase_			).eval()
              UpperCamelCase					 =		model(**UpperCAmelCase_			)

              UpperCamelCase					 =		outputs.encoder_last_hidden_state
              UpperCamelCase					 =		outputs.last_hidden_state

              with tempfile.TemporaryDirectory() as tmpdirname:
                     UpperCamelCase					 =		model.get_encoder()
                     encoder.save_pretrained(UpperCAmelCase_			)
                     UpperCamelCase					 =		MaMaaaEncoder.from_pretrained(UpperCAmelCase_			).to(UpperCAmelCase_			)

              UpperCamelCase					 =		encoder(inputs_dict["input_ids"]       ,      attention_mask=inputs_dict["attention_mask"]			)[
                  0
              ]

              self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1e-3			)

              with tempfile.TemporaryDirectory() as tmpdirname:
                     UpperCamelCase					 =		model.get_decoder()
                     decoder.save_pretrained(UpperCAmelCase_			)
                     UpperCamelCase					 =		MaMaaaDecoder.from_pretrained(UpperCAmelCase_			).to(UpperCAmelCase_			)

              UpperCamelCase					 =		decoder(
                  input_ids=inputs_dict["decoder_input_ids"]       ,      attention_mask=inputs_dict["decoder_attention_mask"]       ,      encoder_hidden_states=UpperCAmelCase_       ,      encoder_attention_mask=inputs_dict["attention_mask"]       ,      )[0]

              self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1e-3			)





@require_torch
class   __a  (      _lowerCAmelCase    ,     _lowerCAmelCase    ,     _lowerCAmelCase    ,     unittest.TestCase	):
       UpperCamelCase_		:					List[str]   =			(
           (
               MaMaaaModel,
               MaMaaaForConditionalGeneration,
           )
           if is_torch_available()
           else ()
       )
       UpperCamelCase_		:					Optional[Any]   =			(MaMaaaForConditionalGeneration,) if is_torch_available() else ()
       UpperCamelCase_		:					int   =			(
           {
               '''conversational''': MaMaaaForConditionalGeneration,
               '''feature-extraction''': MaMaaaModel,
               '''summarization''': MaMaaaForConditionalGeneration,
               '''text2text-generation''': MaMaaaForConditionalGeneration,
               '''translation''': MaMaaaForConditionalGeneration,
           }
           if is_torch_available()
           else {}
       )
       UpperCamelCase_		:					str   =			True
       UpperCamelCase_		:					Tuple   =			True
       UpperCamelCase_		:					str   =			False
       UpperCamelCase_		:					Optional[Any]   =			False






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[str]       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      UpperCAmelCase_ :							Tuple       ,      UpperCAmelCase_ :							str       ,      UpperCAmelCase_ :							List[str]			)->  Any:







              """simple docstring"""
              if pipeline_test_casse_name == "TranslationPipelineTests":
                     # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
                     # `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
                     return True

              return False






       def 	_SCREAMING_SNAKE_CASE       (  self :							str			)->  List[str]:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaModelTester(self			)
              UpperCamelCase					 =		ConfigTester(self       ,      config_class=UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Tuple			)->  Union[str, Any]:







              """simple docstring"""
              self.config_tester.run_common_tests()






       def 	_SCREAMING_SNAKE_CASE       (  self :							Union[str, Any]			)->  Union[str, Any]:







              """simple docstring"""
              UpperCamelCase ,       UpperCamelCase					 =		self.model_tester.prepare_config_and_inputs()
              for model_class in self.all_model_classes:
                     UpperCamelCase					 =		model_class(UpperCAmelCase_			)

                     with tempfile.TemporaryDirectory() as tmpdirname:
                            model.save_pretrained(UpperCAmelCase_			)
                            UpperCamelCase ,       UpperCamelCase					 =		model_class.from_pretrained(UpperCAmelCase_       ,      output_loading_info=UpperCAmelCase_			)
                     self.assertEqual(info["missing_keys"]       ,      []			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict			)->  Optional[int]:







              """simple docstring"""
              UpperCamelCase					 =		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_decoder_model_past_large_inputs(*UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[Any]			)->  Optional[int]:







              """simple docstring"""
              UpperCamelCase					 =		self.model_tester.prepare_config_and_inputs_for_common()
              self.model_tester.check_encoder_decoder_model_standalone(*UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Tuple			)->  List[str]:







              """simple docstring"""
              UpperCamelCase ,       UpperCamelCase					 =		self.model_tester.prepare_config_and_inputs_for_common()

              for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
                     UpperCamelCase					 =		model_class(UpperCAmelCase_			)
                     model.to(UpperCAmelCase_			)
                     model.eval()

                     UpperCamelCase					 =		copy.deepcopy(self._prepare_for_class(UpperCAmelCase_       ,      UpperCAmelCase_			)			)

                     if not self.is_encoder_decoder:
                            UpperCamelCase					 =		inputs["input_ids"]
                            del inputs["input_ids"]
                     else:
                            UpperCamelCase					 =		inputs["input_ids"]
                            UpperCamelCase					 =		inputs.get("decoder_input_ids"       ,      UpperCAmelCase_			)
                            del inputs["input_ids"]
                            inputs.pop("decoder_input_ids"       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		model.get_input_embeddings()
                     if not self.is_encoder_decoder:
                            UpperCamelCase					 =		wte(UpperCAmelCase_			)
                     else:
                            UpperCamelCase					 =		wte(UpperCAmelCase_			)
                            UpperCamelCase					 =		wte(UpperCAmelCase_			)

                     with torch.no_grad():
                            model(**UpperCAmelCase_			)[0]






       def 	_SCREAMING_SNAKE_CASE       (  self :							str			)->  Optional[Any]:







              """simple docstring"""
              UpperCamelCase ,       UpperCamelCase					 =		self.model_tester.prepare_config_and_inputs()
              UpperCamelCase					 =		input_dict["input_ids"]
              UpperCamelCase					 =		input_ids.ne(1			).to(UpperCAmelCase_			)
              UpperCamelCase					 =		MaMaaaForConditionalGeneration(UpperCAmelCase_			).eval().to(UpperCAmelCase_			)
              if torch_device == "cuda":
                     model.half()
              model.generate(UpperCAmelCase_       ,      attention_mask=UpperCAmelCase_			)
              model.generate(num_beams=4       ,      do_sample=UpperCAmelCase_       ,      early_stopping=UpperCAmelCase_       ,      num_return_sequences=3			)





def 	lowerCamelCase__			(							UpperCAmelCase_				)->							Optional[Any]:







       """simple docstring"""
       return torch.tensor(UpperCAmelCase_		,      dtype=torch.long		,      device=UpperCAmelCase_				)


SCREAMING_SNAKE_CASE      =     1E-4



@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class   __a  (      unittest.TestCase	):






       @cached_property
       def 	_SCREAMING_SNAKE_CASE       (  self :							int			)->  Optional[Any]:







              """simple docstring"""
              return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							int			)->  Optional[int]:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaModel.from_pretrained("facebook/m2m100_418M"			).to(UpperCAmelCase_			)
              UpperCamelCase					 =		_long_tensor([[128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38, 2]]			)
              UpperCamelCase					 =		_long_tensor([[2, 128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38]]			)
              UpperCamelCase					 =		prepare_mam_aaa_inputs_dict(model.config       ,      UpperCAmelCase_       ,      UpperCAmelCase_			)
              with torch.no_grad():
                     UpperCamelCase					 =		model(**UpperCAmelCase_			)[0]
              UpperCamelCase					 =		torch.Size((1, 11, 1_024)			)
              self.assertEqual(output.shape       ,      UpperCAmelCase_			)
              # change to expected output here
              UpperCamelCase					 =		torch.tensor(
                  [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]       ,      device=UpperCAmelCase_			)
              self.assertTrue(torch.allclose(output[:, :3, :3]       ,      UpperCAmelCase_       ,      atol=UpperCAmelCase_			)			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[str]			)->  List[Any]:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"			).to(UpperCAmelCase_			)

              # change to intended input
              UpperCamelCase					 =		_long_tensor([[128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38, 2]]			)
              UpperCamelCase					 =		_long_tensor([[2, 128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38]]			)
              UpperCamelCase					 =		prepare_mam_aaa_inputs_dict(model.config       ,      UpperCAmelCase_       ,      UpperCAmelCase_			)
              with torch.no_grad():
                     UpperCamelCase					 =		model(**UpperCAmelCase_			)[0]
              UpperCamelCase					 =		torch.Size((1, 11, model.config.vocab_size)			)
              self.assertEqual(output.shape       ,      UpperCAmelCase_			)
              # change to expected output here
              UpperCamelCase					 =		torch.tensor(
                  [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]       ,      device=UpperCAmelCase_			)
              self.assertTrue(torch.allclose(output[:, :3, :3]       ,      UpperCAmelCase_       ,      atol=UpperCAmelCase_			)			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[Any]			)->  Dict:







              """simple docstring"""
              UpperCamelCase					 =		MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"			).to(UpperCAmelCase_			)
              UpperCamelCase					 =		MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"       ,      src_lang="fr"       ,      tgt_lang="en"			)

              UpperCamelCase					 =		[
                  "L'affaire NSA souligne l'absence totale de débat sur le renseignement",
                  "Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.",
                  "Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"
                  " Fabius convoque l'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"
                  " l'ampleur de la surveillance américaine sur l'ensemble des communications en France.",
              ]

              # The below article tests that we don't add any hypotheses outside of the top n_beams
              UpperCamelCase					 =		tokenizer(UpperCAmelCase_       ,      padding=UpperCAmelCase_       ,      return_tensors="pt"			)

              UpperCamelCase					 =		model.generate(
                  input_ids=dct["input_ids"].to(UpperCAmelCase_			)       ,      attention_mask=dct["attention_mask"].to(UpperCAmelCase_			)       ,      num_beams=5       ,      forced_bos_token_id=tokenizer.get_lang_id("en"			)       ,      )

              UpperCamelCase					 =		[
                  "The NSA case highlights the total absence of intelligence debate",
                  "I think there are two levels of response from the French government.",
                  "When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."
                  " Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"
                  " communications in France.",
              ]

              UpperCamelCase					 =		tokenizer.batch_decode(
                  hypotheses_batch.tolist()       ,      clean_up_tokenization_spaces=UpperCAmelCase_       ,      skip_special_tokens=UpperCAmelCase_			)
              assert generated == expected_en







"""simple docstring"""


import numpy as np

# Importing the Keras libraries and packages
import tensorflow as tf
from tensorflow.keras import layers, models

if __name__ == "__main__":
      # Initialising the CNN
      # (Sequential- Building the model layer by layer)
      SCREAMING_SNAKE_CASE      =     models.Sequential()

      # Step 1 - Convolution
      # Here 64,64 is the length & breadth of dataset images and 3 is for the RGB channel
      # (3,3) is the kernel size (filter matrix)
      classifier.add(
          layers.ConvaD(32, (3, 3), input_shape=(64, 64, 3), activation="""relu""")
      )

      # Step 2 - Pooling
      classifier.add(layers.MaxPoolingaD(pool_size=(2, 2)))

      # Adding a second convolutional layer
      classifier.add(layers.ConvaD(32, (3, 3), activation="""relu"""))
      classifier.add(layers.MaxPoolingaD(pool_size=(2, 2)))

      # Step 3 - Flattening
      classifier.add(layers.Flatten())

      # Step 4 - Full connection
      classifier.add(layers.Dense(units=128, activation="""relu"""))
      classifier.add(layers.Dense(units=1, activation="""sigmoid"""))

      # Compiling the CNN
      classifier.compile(
          optimizer="""adam""", loss="""binary_crossentropy""", metrics=["""accuracy"""]
      )

      # Part 2 - Fitting the CNN to the images

      # Load Trained model weights

      # from keras.models import load_model
      # regressor=load_model('cnn.h5')

      SCREAMING_SNAKE_CASE      =     tf.keras.preprocessing.image.ImageDataGenerator(
          rescale=1.0 / 255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True
      )

      SCREAMING_SNAKE_CASE      =     tf.keras.preprocessing.image.ImageDataGenerator(rescale=1.0 / 255)

      SCREAMING_SNAKE_CASE      =     train_datagen.flow_from_directory(
          """dataset/training_set""", target_size=(64, 64), batch_size=32, class_mode="""binary"""
      )

      SCREAMING_SNAKE_CASE      =     test_datagen.flow_from_directory(
          """dataset/test_set""", target_size=(64, 64), batch_size=32, class_mode="""binary"""
      )

      classifier.fit_generator(
          training_set, steps_per_epoch=5, epochs=30, validation_data=test_set
      )

      classifier.save("""cnn.h5""")

      # Part 3 - Making new predictions

      SCREAMING_SNAKE_CASE      =     tf.keras.preprocessing.image.load_img(
          """dataset/single_prediction/image.png""", target_size=(64, 64)
      )
      SCREAMING_SNAKE_CASE      =     tf.keras.preprocessing.image.img_to_array(test_image)
      SCREAMING_SNAKE_CASE      =     np.expand_dims(test_image, axis=0)
      SCREAMING_SNAKE_CASE      =     classifier.predict(test_image)
      # training_set.class_indices
      if result[0][0] == 0:
            SCREAMING_SNAKE_CASE      =     """Normal"""
      if result[0][0] == 1:
            SCREAMING_SNAKE_CASE      =     """Abnormality detected"""





