| Conditions | 1 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 34 | @click.command() |
||
| 35 | @click.argument('content_image') |
||
| 36 | @click.argument('style_image') |
||
| 37 | @click.option('--interactive', '-i', type=bool, default=True) |
||
| 38 | @click.option('--iterations', '-it', type=int, default=100) |
||
| 39 | @click.option('--location', '-l', type=str, default='.') |
||
| 40 | def cli(content_image, style_image, interactive, iterations, location): |
||
| 41 | |||
| 42 | IMAGE_MODEL_PATH = get_vgg_verydeep_19_model() |
||
| 43 | TERMINATION_CONDITION = 'max-iterations' |
||
| 44 | STYLE_LAYERS = [ |
||
| 45 | ('conv1_1', 0.2), |
||
| 46 | ('conv2_1', 0.2), |
||
| 47 | ('conv3_1', 0.2), |
||
| 48 | ('conv4_1', 0.2), |
||
| 49 | ('conv5_1', 0.2), |
||
| 50 | ] |
||
| 51 | |||
| 52 | image_factory = ImageFactory(Disk.load_image) |
||
| 53 | |||
| 54 | # for now we have hardcoded the config to receive 300 x 400 images with 3 color channels |
||
| 55 | image_process_config = ImageProcessingConfig.from_image_dimensions() |
||
| 56 | |||
| 57 | termination_condition = TerminationConditionFacility.create(TERMINATION_CONDITION, iterations) |
||
| 58 | termination_condition_adapter = TerminationConditionAdapterFactory.create(TERMINATION_CONDITION, termination_condition) |
||
| 59 | print(f' -- Termination Condition: {termination_condition}') |
||
| 60 | |||
| 61 | algorithm_parameters = AlogirthmParameters( |
||
| 62 | image_factory.from_disk(content_image), |
||
| 63 | image_factory.from_disk(style_image), |
||
| 64 | IMAGE_MODEL_PATH, |
||
| 65 | STYLE_LAYERS, |
||
| 66 | termination_condition_adapter, |
||
| 67 | location, |
||
| 68 | ) |
||
| 69 | |||
| 70 | algorithm = NSTAlgorithm(algorithm_parameters, image_process_config) |
||
| 71 | |||
| 72 | algorithm_runner = NSTAlgorithmRunner.default(algorithm, image_factory.image_processor.noisy) |
||
| 73 | |||
| 74 | algorithm_progress = NSTAlgorithmProgress({}) |
||
| 75 | styling_observer = StylingObserver(Disk.save_image) |
||
| 76 | |||
| 77 | algorithm_runner.progress_subject.add( |
||
| 78 | algorithm_progress, |
||
| 79 | termination_condition_adapter, |
||
| 80 | ) |
||
| 81 | algorithm_runner.peristance_subject.add( |
||
| 82 | styling_observer |
||
| 83 | ) |
||
| 84 | |||
| 85 | |||
| 86 | algorithm_runner.run() |
||
| 87 | |||
| 91 |