@@ -88,3 +88,107 @@ cp terraform.tfvars.example terraform.tfvars
8888python ../tools/dockrun.py terraform plan
8989python ../tools/dockrun.py terraform apply
9090```
91+
92+ ## Full training + exporting + hosting commands
93+
94+ Tested with Python 3.6, Tensorflow 1.0.0, Docker, gcloud, and Terraform (https://www.terraform.io/downloads.html )
95+
96+ ``` sh
97+ git clone https://github.com/affinelayer/pix2pix-tensorflow.git
98+ cd pix2pix-tensorflow
99+
100+ # get some images (only 2 for testing)
101+ mkdir source
102+ curl -o source/cat1.jpg https://farm5.staticflickr.com/4032/4394955222_eea73818d9_o.jpg
103+ curl -o source/cat2.jpg http://wallpapercave.com/wp/ePMeSmp.jpg
104+
105+ # resize source images
106+ python tools/process.py \
107+ --input_dir source \
108+ --operation resize \
109+ --output_dir resized
110+
111+ # create edges from resized images (uses docker container since compiling the dependencies is annoying)
112+ python tools/dockrun.py python tools/process.py \
113+ --input_dir resized \
114+ --operation edges \
115+ --output_dir edges
116+
117+ # combine resized with edges
118+ python tools/process.py \
119+ --input_dir edges \
120+ --b_dir resized \
121+ --operation combine \
122+ --output_dir combined
123+
124+ # train on images (only 1 epoch for testing)
125+ python pix2pix.py \
126+ --mode train \
127+ --output_dir train \
128+ --max_epochs 1 \
129+ --input_dir combined \
130+ --which_direction AtoB
131+
132+ # export model (creates a version of the model that works with the server in server/serve.py as well as google hosted tensorflow)
133+ python pix2pix.py \
134+ --mode export \
135+ --output_dir server/models/edges2cats_AtoB \
136+ --checkpoint train
137+
138+ # process image locally using exported model
139+ python server/tools/process-local.py \
140+ --model_dir server/models/edges2cats_AtoB \
141+ --input_file edges/cat1.png \
142+ --output_file output.png
143+
144+ # serve model locally
145+ cd server
146+ python serve.py --port 8000 --local_models_dir models
147+
148+ # open http://localhost:8000 in a browser, and scroll to the bottom, you should be able to process an edges2cat image and get a bunch of noise as output
149+
150+ # serve model remotely
151+
152+ export GOOGLE_PROJECT=< project name>
153+
154+ # build image
155+ # make sure models are in a directory called "models" in the current directory
156+ docker build --rm --tag us.gcr.io/$GOOGLE_PROJECT /pix2pix-server .
157+
158+ # test image locally
159+ docker run --publish 8000:8000 --rm --name server us.gcr.io/$GOOGLE_PROJECT /pix2pix-server python -u serve.py \
160+ --port 8000 \
161+ --local_models_dir models
162+
163+ # run this while the above server is running
164+ python tools/process-remote.py \
165+ --input_file static/edges2cats-input.png \
166+ --url http://localhost:8000/edges2cats_AtoB \
167+ --output_file output.png
168+
169+ # publish image to private google container repository
170+ python tools/upload-image.py --project $GOOGLE_PROJECT --version v1
171+
172+ # create a google cloud server
173+ cp terraform.tfvars.example terraform.tfvars
174+ # edit terraform.tfvars to put your cloud info in there
175+ # get the service-account.json from the google cloud console
176+ # make sure GCE is enabled on your account as well
177+ python terraform plan
178+ python terraform apply
179+
180+ # get name of server
181+ gcloud compute instance-groups list-instances pix2pix-manager
182+ # ssh to server
183+ gcloud compute ssh < name of instance here>
184+ # look at the logs (can take awhile to load docker image)
185+ sudo journalctl -f -u pix2pix
186+ # if you have never made an http-server before, apparently you may need this rule
187+ gcloud compute firewall-rules create http-server --allow=tcp:80 --target-tags http-server
188+ # get ip address of load balancer
189+ gcloud compute forwarding-rules list
190+ # open that in the browser, should see the same page you saw locally
191+
192+ # to destroy the GCP resources, use this
193+ terraform destroy
194+ ```
0 commit comments