<jupyter_start><jupyter_text><jupyter_code>!nvidia-smi -L
%tensorflow_version 1.x
from IPython.display import display,Image as Image2
!git clone https://github.com/vishnukool/stylegan2-ada.git
%cd /content/stylegan2-ada
!pip install awscli
network_pkl = 'network-snapshot-009800.pkl'
!aws s3 cp s3://homely-pretrained-models/$network_pkl ./
from PIL import Image

def showImages(images):
  widths, heights = zip(*(i.size for i in images))

  total_width = sum(widths)
  max_height = max(heights)

  new_im = Image.new('RGB', (total_width, max_height))

  x_offset = 0
  for im in images:
    new_im.paste(im, (x_offset,0))
    x_offset += im.size[0]

  display(new_im)

# -- Gray Traditional -- 
# https://www.ikea.com/gb/en/images/products/ektorp-2-seat-sofa__0818544_pe774475_s5.jpg
# projectPath1 = 'data/a5.jpg'
# outPath1 = 'out/a5'

# -- Recessed Arm Pink -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/41020583/resize-h900-w900%5Ecompr-r85/1069/106985690/Jonas+66.75%27%27+Recessed+Arm+Loveseat+with+Reversible+Cushions.jpg'
# projectPath1 = 'data/a6.jpg'
# outPath1 = 'out/a6'

# -- Pillow top Arm -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/98861474/resize-h310-w310%5Ecompr-r85/1456/145637496/52.75%27%27+Faux+Leather+Pillow+Top+Arm+Reclining.jpg'
# projectPath1 = 'data/a7.jpg'
# outPath1 = 'out/a7'

# -- Gray Modern -- 
# imageUrl = 'https://www.boconcept.com/on/demandware.static/-/Sites-master-catalog/default/dw7429ad62/images/710000/719958.jpg'
# projectPath1 = 'data/a8.jpg'
# outPath1 = 'out/a8'

#  -- White Cushy -- 
# imageUrl = 'https://i.imgur.com/dweqIyf.jpg'
# projectPath1 = 'data/a9.jpg'
# outPath1 = 'out/a9'

# -- Orange Leather Apt Therapy -- 
# imageUrl = 'https://i.imgur.com/C9hZKgN.jpg'
# projectPath1 = 'data/a10.jpg'
# outPath1 = 'out/a10'

# -- Black Leathery -- 
# imageUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSFKW8GkZjfjqVYto6-C8m-6DiwTNeYF2C-8RAgrPq8Au1EUlQkl0Yzs1ycgYILOVXBb6KWNTo&usqp=CAc'
# projectPath1 = 'data/a11.jpg'
# outPath1 = 'out/a11'

# ----

# -- Recessed Arm -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/23871536/resize-h800-w800%5Ecompr-r85/8461/84611427/Cheeky+49.5%27%27+Recessed+Arm+Loveseat.jpg'
# projectPath1 = 'data/a12.jpg'
# outPath1 = 'out/a12'

# -- Recessed Arm 2 -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/53536085/resize-h310-w310%5Ecompr-r85/5520/55205111/default_name.jpg'
# projectPath1 = 'data/a13.jpg'
# outPath1 = 'out/a13'

# -- Recessed Arm 3 -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/65284946/resize-h310-w310%5Ecompr-r85/9910/99107984/Abbott+78%27%27+Recessed+Arm+Sofa.jpg'
# projectPath1 = 'data/a14.jpg'
# outPath1 = 'out/a14'

# -- Wayfair Dark Blue -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/67481968/resize-h800-w800%5Ecompr-r85/1175/117510521/56.69%27%27+Recessed+Arm+Loveseat.jpg'
# projectPath1 = 'data/a15.jpg'
# outPath1 = 'out/a15'

# -- Single Seat Gray -- 
# imageUrl = 'https://loveseat.mx/media/catalog/product/l/o/love_seat_skara_quantum_ash_1.png'
# projectPath1 = 'data/a16.jpg'
# outPath1 = 'out/a16'

# -- Yellow -- 
# imageUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTvY7t9efXRvQ0Dv5btk8-6g9EtL-N8uTeGng&usqp=CAU'
# projectPath1 = 'data/a17.jpg'
# outPath1 = 'out/a17'

# -- Blue Tufted, trouble tufting -- 
# imageUrl = 'https://cdn.shopify.com/s/files/1/2660/5202/products/shopify-image_a6fa3eb1-c388-4ce9-a914-c9ea3e4384cf_1400x.jpg?v=1614976781'
# projectPath1 = 'data/a18.jpg'
# outPath1 = 'out/a18'

# -- Gray Love Seat with Pillows --
# imageUrl = 'https://images.furnituredealer.net/img/products%2Fbenchcraft%2Fcolor%2Fmercado_8460435-b1.jpg'
# projectPath1 = 'data/a19.jpg'
# outPath1 = 'out/a19'

# -- Wayfair Traditional bench seat -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/34805391/resize-h800-w800%5Ecompr-r85/5279/52791200/Cali+49.5%27%27+Loveseat.jpg'
# projectPath1 = 'data/a20.jpg'
# outPath1 = 'out/a20'

# -- Wayfair Flared Arm -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/83196554/resize-h900-w900%5Ecompr-r85/4293/42930166/Erinn+67.25%27%27+Flared+Arm+Loveseat.jpg'
# projectPath1 = 'data/a21.jpg'
# outPath1 = 'out/a21'

# -- Armless -- 
# imageUrl = 'https://secure.img1-fg.wfcdn.com/im/89601253/resize-h800-w800%5Ecompr-r85/4277/42778262/Valeria+55.1%27%27+Armless+Loveseat.jpg'
# projectPath1 = 'data/a22.jpg'
# outPath1 = 'out/a22'

# -- Single Seat but shows 2 seats -- 
# imageUrl = 'https://i.imgur.com/wBkyw6l.jpg'
# projectPath1 = 'data/a23.jpg'
# outPath1 = 'out/a23'

# -- Double Cushion Arm problem -- 
# imageUrl = 'https://moblum.com/media/catalog/product/cache/dc1ae9f78f90a12f86cb0d1e3aec3fb2/s/a/sal54325s1-ruan-gris-obscuro-love_seat-01_1.jpg'
# projectPath1 = 'data/a24.jpg'
# outPath1 = 'out/a24'

# -- Asymmetric pillow top arm -- 
# imageUrl = 'https://mueblesmexico.com/wp-content/uploads/2020/06/Love-Seat-Acord-Warest-Silver.jpg'
# projectPath1 = 'data/a25.jpg'
# outPath1 = 'out/a25'

# -- Sloping Arm, single seat problem -- 
# imageUrl = 'https://mueblesmexico.com/wp-content/uploads/2020/06/Love-Seat-Alicia-Curri-Demin.jpg'
# projectPath1 = 'data/a27.jpg'
# outPath1 = 'out/a27'

# -- Pillow Arm problem
# imageUrl = 'https://cdn1.coppel.com/images/catalog/pm/4237953-3.jpg'
# projectPath1 = 'data/a28.jpg'
# outPath1 = 'out/a28'

# -- Heavy tuft and arm 
# imageUrl = 'https://mueblesmexico.com/wp-content/uploads/2020/06/Love-Seat-Bronx-Velvet-Mustard.jpg'
# projectPath1 = 'data/a29.jpg'
# outPath1 = 'out/a29'

# -- No Idea why --
# imageUrl = 'https://cdn1.coppel.com/images/catalog/pm/4767593-3.jpg'
# projectPath1 = 'data/a30.jpg'
# outPath1 = 'out/a30'

# -- Single seat, sloping arm --
# imageUrl = 'https://mueblesmexico.com/wp-content/uploads/2020/06/Love-Seat-Gandhi-Curri-Demin.jpg'
# projectPath1 = 'data/a31.jpg'
# outPath1 = 'out/a31'

# -- Multi pillow problem --
# imageUrl = 'https://d3uq4j19mzp2q8.cloudfront.net/media/catalog/product/cache/16/image/1200x590/9df78eab33525d08d6e5fb8d27136e95/s/a/sal69587k1-c-f-1-w_1.jpg'
# projectPath1 = 'data/a32.jpg'
# outPath1 = 'out/a32'

# ------------------ ROTATOIN IMAGES --------------------------------

# https://images-na.ssl-images-amazon.com/images/I/61gWcr%2BtWYL._SP1017,567,0%7C518vFSohJkL.jpg,61qEo-+QkUL.jpg,61ysawsCBXL.jpg,51MboY31LXL.jpg,61rRd195GGL.jpg_.jpg
# projectPath1 = 'data/b1.jpg'
# outPath1 = 'out/b1'

# https://www.amazon.com/Versatile-Modern-Storage-Loveseat-Charcoal/dp/B072LT9YC3/ref=sxin_12_ac_d_rm?ac_md=1-1-YXJtbGVzcyBsb3Zlc2VhdA%3D%3D-ac_d_rm_rm_rm&cv_ct_cx=armless+sofa&dchild=1&keywords=armless+sofa&pd_rd_i=B072LT9YC3&pd_rd_r=d8e2d496-4a0f-4955-994d-03b1349e4f0c&pd_rd_w=YdWrj&pd_rd_wg=e1RPV&pf_rd_p=bdf723b2-f1c3-4d1c-967e-60197e162550&pf_rd_r=T2A173RHSM9XN3WPVFCS&psc=1&qid=1627955380&sr=1-2-12d4272d-8adb-4121-8624-135149aa9081
# projectPath1 = 'data/b2.jpg'
# outPath1 = 'out/b2'

# The above link stretched to make it longer
# projectPath1 = 'data/b5.jpg'
# outPath1 = 'out/b5'

# https://www.wayfair.com/furniture/pdp/hashtag-home-valeria-551-armless-loveseat-w004143937.html
# projectPath1 = 'data/b9.jpg'
# outPath1 = 'out/b9'

# https://www.amazon.com/POLY-BARK-Napa-Variation-Cognac/dp/B07QPQCQKQ/ref=sxin_13_ac_d_rm?ac_md=3-1-bGVhdGhlciBzb2Zh-ac_d_rm_rm_rm&cv_ct_cx=sofa&dchild=1&keywords=sofa&pd_rd_i=B07QPQCQKQ&pd_rd_r=df1a7480-5af0-4909-ab06-cdf21b4eb431&pd_rd_w=PhGXb&pd_rd_wg=Y1fba&pf_rd_p=bdf723b2-f1c3-4d1c-967e-60197e162550&pf_rd_r=24ZDVCWSW4VA3N8XVHJN&psc=1&qid=1628008261&sr=1-2-12d4272d-8adb-4121-8624-135149aa9081
# projectPath1 = 'data/c1.jpg'
# outPath1 = 'out/c1'

# https://www.amazon.com/Zinus-Classic-Upholstered-Living-Couch/dp/B079PP84CC/ref=sr_1_5?dchild=1&keywords=sofa&qid=1628008831&s=home-garden&sr=1-5
# Side View
# projectPath1 = 'data/c2.jpg'
# outPath1 = 'out/c2'

projectPath1 = 'data/c4.jpg'
outPath1 = 'out/c4'
!python projector.py --outdir=$outPath1 --target=$projectPath1 --save-video=False --network=./network-snapshot-009800.pkl

showImages([Image.open('./' + outPath1+'/target.png'), Image.open('./' + outPath1+'/proj.png')])
import dnnlib
import dnnlib.tflib as tflib
import pickle
import numpy as np
from PIL import Image

Gs_syn_kwargs = {
    'output_transform': dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True),
    'randomize_noise': False,
    'minibatch_size': 4
}
tflib.init_tf()
with dnnlib.util.open_url(network_pkl) as fp:
  _G, _D, Gs = pickle.load(fp)

angleLatentPath = 'out/a27'
styleLatentPath = 'out/c3'

# display(Image2(filename='./' + angleLatentPath+'/proj.png'))
# display(Image2(filename='./' + styleLatentPath+'/proj.png'))

with np.load(angleLatentPath + '/dlatents.npz') as latent1:
  with np.load(styleLatentPath + '/dlatents.npz') as latent2:
    lat1 = latent1['dlatents']
    lat2 = latent2['dlatents']
    col_styles = [3,4,5,6,7,8,9,10,11,12,13]
    lat1[0][col_styles] = lat2[0][col_styles]
    image = Gs.components.synthesis.run(lat1, **Gs_syn_kwargs)[0]

    mixImg = Image.fromarray(image, 'RGB')
    showImages([Image.open('./' + angleLatentPath+'/proj.png'),Image.open('./' + styleLatentPath+'/proj.png') ,mixImg])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1803818301514154, 'fraction_numerical': 0.11586570111915734, 'mean_word_length': 4.39668442865601, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 33, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '12591', 'license': 'BSD-Source-Code', 'n_tokens_mistral': 4769, 'n_tokens_neox': 4247, 'n_words': 427, 'path': 'style_mixing.ipynb', 'repo_name': 'vishnukool/stylegan2-ada', 'size': '9114'}