{"id":28461029,"url":"https://github.com/asrot0/neuralstyletransferart","last_synced_at":"2026-05-17T02:03:16.909Z","repository":{"id":292010112,"uuid":"977596843","full_name":"asRot0/NeuralStyleTransferArt","owner":"asRot0","description":"Create artistic images by blending the content of one image with the style of another using VGG19 and custom loss functions. Combines deep learning with image generation techniques.","archived":false,"fork":false,"pushed_at":"2025-05-22T13:09:16.000Z","size":3509,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T06:39:06.127Z","etag":null,"topics":["aesthetic-ai","deep-learning","image-processing","neural-style-transfer","tensorflow","vgg19"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asRot0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-04T15:12:38.000Z","updated_at":"2025-05-23T13:24:59.000Z","dependencies_parsed_at":"2025-05-07T17:43:43.776Z","dependency_job_id":"b00920e1-2b32-44cd-92cc-38cb270b5e17","html_url":"https://github.com/asRot0/NeuralStyleTransferArt","commit_stats":null,"previous_names":["asrot0/neuralstyletransferart"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/asRot0/NeuralStyleTransferArt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asRot0%2FNeuralStyleTransferArt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asRot0%2FNeuralStyleTransferArt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asRot0%2FNeuralStyleTransferArt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asRot0%2FNeuralStyleTransferArt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asRot0","download_url":"https://codeload.github.com/asRot0/NeuralStyleTransferArt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asRot0%2FNeuralStyleTransferArt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281092773,"owners_count":26442440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aesthetic-ai","deep-learning","image-processing","neural-style-transfer","tensorflow","vgg19"],"created_at":"2025-06-07T03:07:25.355Z","updated_at":"2025-10-26T10:46:07.886Z","avatar_url":"https://github.com/asRot0.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural Style Transfer with TensorFlow and VGG19\n\nThis project implements **Neural Style Transfer (NST)** using TensorFlow 2 and a pretrained **VGG19** network. The goal is to generate a new image that combines the **content of one image** with the **artistic style of another**.\n\n## What is Neural Style Transfer?\n\nNeural Style Transfer is a deep learning technique that separates and recombines **content** and **style** from two images using feature maps extracted from a convolutional neural network.\n\n- **Content Image**: Defines the structure or semantics.\n- **Style Image**: Defines texture, color, and patterns.\n- **Generated Image**: Optimized to preserve content from the content image and style from the style image.\n\nHere is how Neural Style Transfer blends the **content** and **style** images:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"image/mona_lisa.jpg\" width=\"200px\"\u003e\n  \u003cimg src=\"image/edtaonisl.jpg\" width=\"298px\"\u003e\n  \u003cimg src=\"image/stylized-image1.png\" width=\"200px\"\u003e\n\u003c/p\u003e\n\n\u003e The output preserves the structure of the content image and adopts the texture, brush strokes, and colors of the style image.\n\n\n\n## How It Works\n\nNST uses a pretrained CNN (typically VGG19) to extract features from content and style images. These features are used to calculate losses that guide the generated image to match the desired output.\n\n### Feature Extraction\n\n- Extract intermediate feature maps from VGG19.\n- Use `block5_conv2` for content representation.\n- Use multiple layers (`block1_conv1`, ..., `block5_conv1`) for style representation.\n\n## Math Behind the Losses\n\n### Content Loss\n\nMeasures the difference between the feature representations of the content image and the generated image.\n\n```math\n\\LARGE \\mathcal{L}_{content}(C, G) = \\frac{1}{2} \\sum_{i,j} (F_{ij}^C - F_{ij}^G)^2\n```\n\nWhere:\n- $`F_{ij}^C`$: Feature map of the content image at position \\(i, j\\)\n- $`F_{ij}^G`$: Feature map of the generated image\n\n### Style Loss\n\nMeasures the difference between the style (texture and pattern) of the style image and the generated image using **Gram matrices**.\n\n#### Gram Matrix\n\nThe Gram matrix captures the correlation between feature maps:\n\n```math\n\\LARGE G^l_{ij} = \\sum_k F^l_{ik} F^l_{jk}\n```\n\nIn code, this is implemented efficiently using:\n\n```python\ntf.linalg.einsum('bijc,bijd-\u003ebcd', input_tensor, input_tensor)\n```\n\nThis computes the inner products between feature channels to form the Gram matrix.\n\n#### Style Loss Formula\n\n```math\n\\LARGE \\mathcal{L}_{style}(S, G) = \\sum_{l=1}^{L} \\frac{1}{4N_l^2M_l^2} \\sum_{i,j} (G^S_{ij} - G^G_{ij})^2\n```\n\nWhere:\n- $`L`$: Number of selected style layers\n- $`N_l`$: Number of filters in layer $`l`$\n- $`M_l`$: Spatial size of the feature map\n\n### Total Loss\n\nCombines content and style losses:\n\n```math\n\\LARGE \\mathcal{L}_{total} = \\alpha \\cdot \\mathcal{L}_{content} + \\beta \\cdot \\mathcal{L}_{style}\n```\n\nWhere:\n- $`\\alpha`$: Weight for content loss (e.g., 1e4)\n- $`\\beta`$: Weight for style loss (e.g., 1e-2)\n\n\u003e “Art enables us to find ourselves and lose ourselves at the same time.” – Thomas Merton\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"image/content.jpg\" width=\"150px\"\u003e\n  \u003cimg src=\"image/style.jpg\" width=\"326px\"\u003e\n  \u003cimg src=\"image/stylized-image4.png\" width=\"150px\"\u003e\n  \u003cbr\u003e\n  \u003cimg src=\"image/cartoon.jpg\" width=\"150px\"\u003e\n  \u003cimg src=\"image/style1.jpg\" width=\"281px\"\u003e\n  \u003cimg src=\"image/stylized-image5.png\" width=\"150px\"\u003e\n\u003c/p\u003e\n\n\n## Training Process\n\n1. Initialize the generated image as a copy of the content image.\n2. Extract target features from the content and style images.\n3. Use `tf.GradientTape` to compute gradients of the total loss w.r.t. the generated image.\n4. Update the image using an optimizer (e.g., Adam).\n5. Clip pixel values between 0 and 1.\n6. Repeat for multiple epochs.\n\n## Layers Used\n\n| Type     | Layer Name       | Purpose                   |\n|----------|------------------|---------------------------|\n| Content  | `block5_conv2`    | Preserve structure        |\n| Style    | `block1_conv1`    | Capture low-level textures |\n|          | `block2_conv1`    |                           |\n|          | `block3_conv1`    |                           |\n|          | `block4_conv1`    |                           |\n|          | `block5_conv1`    | Capture abstract style    |\n\n## References\n\n- Gatys et al. (2015), *“A Neural Algorithm of Artistic Style”* — https://arxiv.org/abs/1508.06576\n- TensorFlow Style Transfer Tutorial — https://www.tensorflow.org/tutorials/generative/style_transfer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasrot0%2Fneuralstyletransferart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasrot0%2Fneuralstyletransferart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasrot0%2Fneuralstyletransferart/lists"}