"""simple docstring"""



import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
     from PIL import Image

class SCREAMING_SNAKE_CASE     (    unittest.TestCase   ,      a	):







 """simple docstring"""


 def        _lowerCAmelCase				(   self		:      Any				)				->			Dict:




    '''simple docstring'''






    a__     				=		load_tool('image-captioning'				)
    self.tool.setup()
    a__     				=		load_tool('image-captioning'					,   remote=_snake_case				)


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




    '''simple docstring'''






    a__     				=		Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'				)				) / '000000039769.png'				)
    a__     				=		self.tool(_snake_case				)
    self.assertEqual(_snake_case					,   'two cats sleeping on a couch'				)


 def        _lowerCAmelCase				(   self		:      int				)				->			Dict:




    '''simple docstring'''






    a__     				=		Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'				)				) / '000000039769.png'				)
    a__     				=		self.remote_tool(_snake_case				)
    self.assertEqual(_snake_case					,   'two cats sleeping on a couch'				)


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




    '''simple docstring'''






    a__     				=		Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'				)				) / '000000039769.png'				)
    a__     				=		self.tool(image=_snake_case				)
    self.assertEqual(_snake_case					,   'two cats sleeping on a couch'				)



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




    '''simple docstring'''






    a__     				=		Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'				)				) / '000000039769.png'				)
    a__     				=		self.remote_tool(image=_snake_case				)
    self.assertEqual(_snake_case					,   'two cats sleeping on a couch'				)



"""simple docstring"""



import argparse

from transformers import CanineConfig, CanineModel, CanineTokenizer, load_tf_weights_in_canine
from transformers.utils import logging


logging.set_verbosity_info()





def   _lowerCamelCase ( UpperCAmelCase__,UpperCAmelCase__					)							->     Optional[int]:


   '''simple docstring'''


   a__     				=		CanineConfig()
   a__     				=		CanineModel(UpperCAmelCase__					)
   model.eval()

   print(f'''Building PyTorch model from configuration: {config}'''					)

   # Load weights from tf checkpoint
   load_tf_weights_in_canine(UpperCAmelCase__,UpperCAmelCase__,UpperCAmelCase__					)

   # Save pytorch-model (weights and configuration)
   print(f'''Save PyTorch model to {pytorch_dump_path}'''					)
   model.save_pretrained(UpperCAmelCase__					)

   # Save tokenizer files
   a__     				=		CanineTokenizer()
   print(f'''Save tokenizer files to {pytorch_dump_path}'''					)
   tokenizer.save_pretrained(UpperCAmelCase__					)


if __name__ == "__main__":
     __magic_name__    				=					argparse.ArgumentParser()
     # Required parameters
     parser.add_argument(
         "--tf_checkpoint_path",
         default=None,
         type=str,
         required=True,
         help="Path to the TensorFlow checkpoint. Should end with model.ckpt",
     )
     parser.add_argument(
         "--pytorch_dump_path",
         default=None,
         type=str,
         required=True,
         help="Path to a folder where the PyTorch model will be placed.",
     )
     __magic_name__    				=					parser.parse_args()
     convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.pytorch_dump_path)


