


import copy
import inspect
import unittest

from transformers import PretrainedConfig, SwiftFormerConfig
from transformers.testing_utils import (
    require_torch,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import SwiftFormerForImageClassification, SwiftFormerModel
			from transformers.models.swiftformer.modeling_swiftformer import SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import ViTImageProcessor


class 	_a							:

							def __init__(							self:     int   ,						UpperCamelCase_:     Optional[Any]   ,						UpperCamelCase_:     Any=13   ,						UpperCamelCase_:     Dict=3   ,						UpperCamelCase_:     List[Any]=True   ,						UpperCamelCase_:     Optional[Any]=True   ,						UpperCamelCase_:     Union[str, Any]=0.1   ,						UpperCamelCase_:     str=0.1   ,						UpperCamelCase_:     Tuple=224   ,						UpperCamelCase_:     Optional[Any]=1_000   ,						UpperCamelCase_:     List[Any]=[3, 3, 6, 4]   ,						UpperCamelCase_:     Union[str, Any]=[48, 56, 112, 220]   ,						)      ->       str:





									"""simple docstring"""







									lowercase__						=				parent
									lowercase__						=				batch_size
									lowercase__						=				num_channels
									lowercase__						=				is_training
									lowercase__						=				use_labels
									lowercase__						=				hidden_dropout_prob
									lowercase__						=				attention_probs_dropout_prob
									lowercase__						=				num_labels
									lowercase__						=				image_size
									lowercase__						=				layer_depths
									lowercase__						=				embed_dims

							def 				lowerCamelCase_			(							self:     List[str]							)      ->       Dict:





									"""simple docstring"""







									lowercase__						=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

									lowercase__						=				None
									if self.use_labels:
											lowercase__						=				ids_tensor([self.batch_size]   ,						self.num_labels							)

									lowercase__						=				self.get_config()

									return config, pixel_values, labels

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





									"""simple docstring"""







									return SwiftFormerConfig(
									    depths=self.layer_depths   ,						embed_dims=self.embed_dims   ,						mlp_ratio=4   ,						downsamples=[True, True, True, True]   ,						hidden_act='''gelu'''   ,						num_labels=self.num_labels   ,						down_patch_size=3   ,						down_stride=2   ,						down_pad=1   ,						drop_rate=0.0   ,						drop_path_rate=0.0   ,						use_layer_scale=UpperCAmelCase_   ,						layer_scale_init_value=1E-5   ,						)

							def 				lowerCamelCase_			(							self:     Dict   ,						UpperCamelCase_:     Any   ,						UpperCamelCase_:     Dict   ,						UpperCamelCase_:     Union[str, Any]							)      ->       List[str]:





									"""simple docstring"""







									lowercase__						=				SwiftFormerModel(config=UpperCAmelCase_							)
									model.to(UpperCAmelCase_							)
									model.eval()
									lowercase__						=				model(UpperCAmelCase_							)
									self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, self.embed_dims[-1], 7, 7)							)

							def 				lowerCamelCase_			(							self:     Any   ,						UpperCamelCase_:     Optional[int]   ,						UpperCamelCase_:     Union[str, Any]   ,						UpperCamelCase_:     List[Any]							)      ->       Tuple:





									"""simple docstring"""







									lowercase__						=				self.num_labels
									lowercase__						=				SwiftFormerForImageClassification(UpperCAmelCase_							)
									model.to(UpperCAmelCase_							)
									model.eval()
									lowercase__						=				model(UpperCAmelCase_   ,						labels=UpperCAmelCase_							)
									self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels)							)

									lowercase__						=				SwiftFormerForImageClassification(UpperCAmelCase_							)
									model.to(UpperCAmelCase_							)
									model.eval()

									lowercase__						=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)
									lowercase__						=				model(UpperCAmelCase_							)
									self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels)							)


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





									"""simple docstring"""







									(lowercase__)						=				self.prepare_config_and_inputs()
									lowercase__						=				{"pixel_values": pixel_values}
									return config, inputs_dict


@require_torch
class 	_a							(      snake_case__					,     snake_case__					,     unittest.TestCase      ):
							_lowercase     :      int  				=			(SwiftFormerModel, SwiftFormerForImageClassification) if is_torch_available() else ()
							_lowercase     :      Optional[Any]  				=			(
							    {'''feature-extraction''': SwiftFormerModel, '''image-classification''': SwiftFormerForImageClassification}
							    if is_torch_available()
							    else {}
							)

							_lowercase     :      List[str]  				=			False
							_lowercase     :      int  				=			False
							_lowercase     :      Tuple  				=			False
							_lowercase     :      List[Any]  				=			False
							_lowercase     :      Any  				=			False

							def 				lowerCamelCase_			(							self:     Any							)      ->       Optional[Any]:





									"""simple docstring"""







									lowercase__						=				SwiftFormerModelTester(self							)
									lowercase__						=				ConfigTester(
									    self   ,						config_class=UpperCAmelCase_   ,						has_text_modality=UpperCAmelCase_   ,						hidden_size=37   ,						num_attention_heads=12   ,						num_hidden_layers=12   ,						)

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





									"""simple docstring"""







									self.config_tester.run_common_tests()

							@unittest.skip(reason='''SwiftFormer does not use inputs_embeds'''							)
							def 				lowerCamelCase_			(							self:     Tuple							)      ->       Optional[int]:





									"""simple docstring"""







									pass

							def 				lowerCamelCase_			(							self:     List[str]							)      ->       Optional[int]:





									"""simple docstring"""







									lowercase__						=				self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											lowercase__						=				model_class(UpperCAmelCase_							)
											lowercase__						=				model.get_output_embeddings()
											self.assertTrue(x is None or isinstance(UpperCAmelCase_   ,						nn.Linear							)							)

							def 				lowerCamelCase_			(							self:     Optional[int]							)      ->       Union[str, Any]:





									"""simple docstring"""







									lowercase__						=				self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											lowercase__						=				model_class(UpperCAmelCase_							)
											lowercase__						=				inspect.signature(model.forward							)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											lowercase__						=				[*signature.parameters.keys()]

											lowercase__						=				["pixel_values"]
											self.assertListEqual(arg_names[:1]   ,						UpperCAmelCase_							)

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





									"""simple docstring"""







									lowercase__						=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*UpperCAmelCase_							)

							def 				lowerCamelCase_			(							self:     Tuple							)      ->       str:





									"""simple docstring"""







									lowercase__						=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase_							)

							@slow
							def 				lowerCamelCase_			(							self:     List[str]							)      ->       Dict:





									"""simple docstring"""







									for model_name in SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											lowercase__						=				SwiftFormerModel.from_pretrained(UpperCAmelCase_							)
											self.assertIsNotNone(UpperCAmelCase_							)

							@unittest.skip(reason='''SwiftFormer does not output attentions'''							)
							def 				lowerCamelCase_			(							self:     Dict							)      ->       Dict:





									"""simple docstring"""







									pass

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





									"""simple docstring"""







									def check_hidden_states_output(UpperCamelCase_:     Optional[Any]   ,						UpperCamelCase_:     int   ,						UpperCamelCase_:     str							):
											lowercase__						=				model_class(UpperCAmelCase_							)
											model.to(UpperCAmelCase_							)
											model.eval()

											with torch.no_grad():
													lowercase__						=				model(**self._prepare_for_class(UpperCAmelCase_   ,						UpperCAmelCase_							)							)

											lowercase__						=				outputs.hidden_states

											lowercase__						=				8
											self.assertEqual(len(UpperCAmelCase_							)   ,						UpperCAmelCase_							)  # TODO

											# SwiftFormer's feature maps are of shape (batch_size, embed_dims, height, width)
											# with the width and height being successively divided by 2, after every 2 blocks
											for i in range(len(UpperCAmelCase_							)							):
													self.assertEqual(
													    hidden_states[i].shape   ,						torch.Size(
													        [
													            self.model_tester.batch_size,
													            self.model_tester.embed_dims[i // 2],
													            (self.model_tester.image_size // 4) // 2 ** (i // 2),
													            (self.model_tester.image_size // 4) // 2 ** (i // 2),
													        ]							)   ,						)

									lowercase__						=				self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											lowercase__						=				True
											check_hidden_states_output(UpperCAmelCase_   ,						UpperCAmelCase_   ,						UpperCAmelCase_							)

											# check that output_hidden_states also work using config
											del inputs_dict["output_hidden_states"]
											lowercase__						=				True

											check_hidden_states_output(UpperCAmelCase_   ,						UpperCAmelCase_   ,						UpperCAmelCase_							)

							def 				lowerCamelCase_			(							self:     List[str]							)      ->       int:





									"""simple docstring"""







									def _config_zero_init(UpperCamelCase_:     int							):
											lowercase__						=				copy.deepcopy(UpperCAmelCase_							)
											for key in configs_no_init.__dict__.keys():
													if "_range" in key or "_std" in key or "initializer_factor" in key or "layer_scale" in key:
															setattr(UpperCAmelCase_   ,						UpperCAmelCase_   ,						1E-1_0							)
													if isinstance(getattr(UpperCAmelCase_   ,						UpperCAmelCase_   ,						UpperCAmelCase_							)   ,						UpperCAmelCase_							):
															lowercase__						=				_config_zero_init(getattr(UpperCAmelCase_   ,						UpperCAmelCase_							)							)
															setattr(UpperCAmelCase_   ,						UpperCAmelCase_   ,						UpperCAmelCase_							)
											return configs_no_init

									lowercase__						=				self.model_tester.prepare_config_and_inputs_for_common()

									lowercase__						=				_config_zero_init(UpperCAmelCase_							)
									for model_class in self.all_model_classes:
											lowercase__						=				model_class(config=UpperCAmelCase_							)
											for name, param in model.named_parameters():
													if param.requires_grad:
															self.assertIn(
															    ((param.data.mean() * 1E9) / 1E9).round().item()   ,						[0.0, 1.0]   ,						msg=f'Parameter {name} of model {model_class} seems not properly initialized'   ,						)


							@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
							def 				lowerCamelCase_			(							self:     str							)      ->       List[Any]:





									"""simple docstring"""







									pass
def       _a			(				):


		"""simple docstring"""




		lowercase__						=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					)
		return image


@require_torch
@require_vision
class 	_a							(      unittest.TestCase      ):

							@cached_property
							def 				lowerCamelCase_			(							self:     str							)      ->       List[str]:





									"""simple docstring"""







									return ViTImageProcessor.from_pretrained('''MBZUAI/swiftformer-xs'''							) if is_vision_available() else None


							@slow
							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       Optional[int]:





									"""simple docstring"""







									lowercase__						=				SwiftFormerForImageClassification.from_pretrained('''MBZUAI/swiftformer-xs'''							).to(UpperCAmelCase_							)

									lowercase__						=				self.default_image_processor
									lowercase__						=				prepare_img()
									lowercase__						=				image_processor(images=UpperCAmelCase_   ,						return_tensors='''pt'''							).to(UpperCAmelCase_							)

									# forward pass
									with torch.no_grad():
											lowercase__						=				model(**UpperCAmelCase_							)

									# verify the logits
									lowercase__						=				torch.Size((1, 1_000)							)
									self.assertEqual(outputs.logits.shape   ,						UpperCAmelCase_							)

									lowercase__						=				torch.tensor([[-2.1_7_0_3E0_0, 2.1_1_0_7E0_0, -2.0_8_1_1E0_0]]							).to(UpperCAmelCase_							)
									self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,						UpperCAmelCase_   ,						atol=1E-4							)							)






import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, XLMRobertaTokenizer

from diffusers import AltDiffusionPipeline, AutoencoderKL, DDIMScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()


class 	_a							(      UpperCamelCase__					,     UpperCamelCase__					,     UpperCamelCase__					,     unittest.TestCase      ):
							_lowercase     :      int  				=			AltDiffusionPipeline
							_lowercase     :      Tuple  				=			TEXT_TO_IMAGE_PARAMS
							_lowercase     :      List[str]  				=			TEXT_TO_IMAGE_BATCH_PARAMS
							_lowercase     :      Union[str, Any]  				=			TEXT_TO_IMAGE_IMAGE_PARAMS
							_lowercase     :      int  				=			TEXT_TO_IMAGE_IMAGE_PARAMS

							def 				lowerCamelCase_			(							self:     Optional[int]							)      ->       Union[str, Any]:





									"""simple docstring"""







									torch.manual_seed(0							)
									lowercase__						=				UNetaDConditionModel(
									    block_out_channels=(32, 64)   ,						layers_per_block=2   ,						sample_size=32   ,						in_channels=4   ,						out_channels=4   ,						down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')   ,						up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')   ,						cross_attention_dim=32   ,						)
									lowercase__						=				DDIMScheduler(
									    beta_start=0.00085   ,						beta_end=0.012   ,						beta_schedule='''scaled_linear'''   ,						clip_sample=UpperCamelCase_   ,						set_alpha_to_one=UpperCamelCase_   ,						)
									torch.manual_seed(0							)
									lowercase__						=				AutoencoderKL(
									    block_out_channels=[32, 64]   ,						in_channels=3   ,						out_channels=3   ,						down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']   ,						up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']   ,						latent_channels=4   ,						)

									# TODO: address the non-deterministic text encoder (fails for save-load tests)
									# torch.manual_seed(0)
									# text_encoder_config = RobertaSeriesConfig(
									#     hidden_size=32,
									#     project_dim=32,
									#     intermediate_size=37,
									#     layer_norm_eps=1e-05,
									#     num_attention_heads=4,
									#     num_hidden_layers=5,
									#     vocab_size=5002,
									# )
									# text_encoder = RobertaSeriesModelWithTransformation(text_encoder_config)

									torch.manual_seed(0							)
									lowercase__						=				CLIPTextConfig(
									    bos_token_id=0   ,						eos_token_id=2   ,						hidden_size=32   ,						projection_dim=32   ,						intermediate_size=37   ,						layer_norm_eps=1E-0_5   ,						num_attention_heads=4   ,						num_hidden_layers=5   ,						pad_token_id=1   ,						vocab_size=5_002   ,						)
									lowercase__						=				CLIPTextModel(UpperCamelCase_							)

									lowercase__						=				XLMRobertaTokenizer.from_pretrained('''hf-internal-testing/tiny-xlm-roberta'''							)
									lowercase__						=				77

									lowercase__						=				{
									    '''unet''': unet,
									    '''scheduler''': scheduler,
									    '''vae''': vae,
									    '''text_encoder''': text_encoder,
									    '''tokenizer''': tokenizer,
									    '''safety_checker''': None,
									    '''feature_extractor''': None,
									}
									return components

							def 				lowerCamelCase_			(							self:     List[str]   ,						UpperCamelCase_:     Optional[int]   ,						UpperCamelCase_:     str=0							)      ->       Union[str, Any]:





									"""simple docstring"""







									if str(UpperCamelCase_							).startswith('''mps'''							):
											lowercase__						=				torch.manual_seed(UpperCamelCase_							)
									else:
											lowercase__						=				torch.Generator(device=UpperCamelCase_							).manual_seed(UpperCamelCase_							)
									lowercase__						=				{
									    '''prompt''': '''A painting of a squirrel eating a burger''',
									    '''generator''': generator,
									    '''num_inference_steps''': 2,
									    '''guidance_scale''': 6.0,
									    '''output_type''': '''numpy''',
									}
									return inputs

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





									"""simple docstring"""







									super().test_attention_slicing_forward_pass(expected_max_diff=3E-3							)

							def 				lowerCamelCase_			(							self:     Dict							)      ->       str:





									"""simple docstring"""







									super().test_inference_batch_single_identical(expected_max_diff=3E-3							)

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





									"""simple docstring"""







									lowercase__						=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator

									lowercase__						=				self.get_dummy_components()
									torch.manual_seed(0							)
									lowercase__						=				RobertaSeriesConfig(
									    hidden_size=32   ,						project_dim=32   ,						intermediate_size=37   ,						layer_norm_eps=1E-0_5   ,						num_attention_heads=4   ,						num_hidden_layers=5   ,						vocab_size=5_002   ,						)
									# TODO: remove after fixing the non-deterministic text encoder
									lowercase__						=				RobertaSeriesModelWithTransformation(UpperCamelCase_							)
									lowercase__						=				text_encoder

									lowercase__						=				AltDiffusionPipeline(**UpperCamelCase_							)
									lowercase__						=				alt_pipe.to(UpperCamelCase_							)
									alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

									lowercase__						=				self.get_dummy_inputs(UpperCamelCase_							)
									lowercase__						=				'''A photo of an astronaut'''
									lowercase__						=				alt_pipe(**UpperCamelCase_							)
									lowercase__						=				output.images
									lowercase__						=				image[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)
									lowercase__						=				np.array(
									    [0.5748162, 0.60447145, 0.48821217, 0.50100636, 0.5431185, 0.45763683, 0.49657696, 0.48132733, 0.47573093]							)

									assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2


							def 				lowerCamelCase_			(							self:     Optional[Any]							)      ->       Tuple:





									"""simple docstring"""







									lowercase__						=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator

									lowercase__						=				self.get_dummy_components()
									lowercase__						=				PNDMScheduler(skip_prk_steps=UpperCamelCase_							)
									torch.manual_seed(0							)
									lowercase__						=				RobertaSeriesConfig(
									    hidden_size=32   ,						project_dim=32   ,						intermediate_size=37   ,						layer_norm_eps=1E-0_5   ,						num_attention_heads=4   ,						num_hidden_layers=5   ,						vocab_size=5_002   ,						)
									# TODO: remove after fixing the non-deterministic text encoder
									lowercase__						=				RobertaSeriesModelWithTransformation(UpperCamelCase_							)
									lowercase__						=				text_encoder
									lowercase__						=				AltDiffusionPipeline(**UpperCamelCase_							)
									lowercase__						=				alt_pipe.to(UpperCamelCase_							)
									alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

									lowercase__						=				self.get_dummy_inputs(UpperCamelCase_							)
									lowercase__						=				alt_pipe(**UpperCamelCase_							)
									lowercase__						=				output.images
									lowercase__						=				image[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)
									lowercase__						=				np.array(
									    [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237]							)

									assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2


@slow
@require_torch_gpu
class 	_a							(      unittest.TestCase      ):

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





									"""simple docstring"""







									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()

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





									"""simple docstring"""







									lowercase__						=				AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion'''   ,						safety_checker=UpperCamelCase_							)
									lowercase__						=				alt_pipe.to(UpperCamelCase_							)
									alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

									lowercase__						=				'''A painting of a squirrel eating a burger'''
									lowercase__						=				torch.manual_seed(0							)
									lowercase__						=				alt_pipe([prompt]   ,						generator=UpperCamelCase_   ,						guidance_scale=6.0   ,						num_inference_steps=20   ,						output_type='''np'''							)

									lowercase__						=				output.images

									lowercase__						=				image[0, -3:, -3:, -1]

									assert image.shape == (1, 512, 512, 3)
									lowercase__						=				np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586]							)

									assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2


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





									"""simple docstring"""







									lowercase__						=				DDIMScheduler.from_pretrained('''BAAI/AltDiffusion'''   ,						subfolder='''scheduler'''							)

									lowercase__						=				AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion'''   ,						scheduler=UpperCamelCase_   ,						safety_checker=UpperCamelCase_							)
									lowercase__						=				alt_pipe.to(UpperCamelCase_							)
									alt_pipe.set_progress_bar_config(disable=UpperCamelCase_							)

									lowercase__						=				'''A painting of a squirrel eating a burger'''
									lowercase__						=				torch.manual_seed(0							)

									lowercase__						=				alt_pipe([prompt]   ,						generator=UpperCamelCase_   ,						num_inference_steps=2   ,						output_type='''numpy'''							)
									lowercase__						=				output.images

									lowercase__						=				image[0, -3:, -3:, -1]

									assert image.shape == (1, 512, 512, 3)
									lowercase__						=				np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323]							)

									assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2


