# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="aegpLsoGi9o7" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} outputId="70bd72fe-0261-4659-df4e-07756c6cb4d0"
import os
from google.colab import drive
drive.mount('/content/drive')
home = '/content/drive/My Drive/Forams'
os.chdir(home)
# !git clone https://github.com/metazool/forambulator

# + id="IMHKG0GZorDv" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 201} outputId="6e151e6a-d514-4234-e8f3-421b689ccca4"
import os, sys
home = '/content/drive/My Drive/Forams'
os.chdir(home)
os.chdir('forambulator')
# !git pull
os.chdir(home)
import sys
sys.path.append('./forambulator')

# + id="vCbD-zpMIP6h" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 79} outputId="7b8e68ec-9313-40ee-dac5-58b080ed7f1d"
# from forams.images import list_image_filenames, crop_foram
# images = list_image_filenames('./cropped_forams')
# len(images)

# + id="fhxPxNITJBVr" colab_type="code" colab={}
# images = list_image_filenames('./data')
# for image in images:
#     crop_foram(image)

# + id="0bfRAlXzLeAL" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 187} outputId="6bb80e9d-a343-4652-fda9-42e9988841c1"
from forams.images import tfrecords_from_images
tfrecords_from_images('./tfrecords','./cropped_forams', True)

# + id="PGPufeX4muVs" colab_type="code" colab={}
# import sys
# sys.path.append('forambulator')
# from forams_download import download_capsules
# download_capsules()

# + [markdown] id="AZzzYEEU2U7v" colab_type="text"
# This next section based on the stylegan-art transfer learning notebook forked here: 
# https://github.com/metazool/stylegan-art/blob/master/styleganportraits.ipynb
# First: download latest model for transfer learning

# + id="jdBnJcvm2gyX" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 84} outputId="6bf666da-c928-4d02-bf9c-2348dbc40232"
# !gdown https://drive.google.com/uc?id=1cJQtMeTy_QldOP7n64F8stCDXY6Esup9

# + [markdown] id="ZJK_uxUrPVSz" colab_type="text"
# Add the stylegan-art repo for dnnlib
#

# + id="PlReG07PPR6g" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 67} outputId="a2c3dd40-8e59-482e-d0db-7311f209ab49"
# !git clone https://github.com/metazool/stylegan-art
os.chdir('stylegan-art')
# !git pull
os.chdir(home)
# !pip install -r stylegan-art/requirements.txt
sys.path.append('stylegan-art')

# + id="CCv4EmYWWDee" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="807461f5-1c80-43c1-b5b7-8f64354004b5"

import forams.train
forams.train.train(tfrecord_dir=os.path.join(home, 'tfrecords'))


# + id="769GrsjmYQB-" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 117} outputId="648acd17-2a8c-4a38-df9d-2707398b9c97"
os.listdir('./tfrecords')

StarcoderdataJupyterScriptsDedupFiltered