Advertisement
Guest User

wav-ns.sh

a guest
Aug 7th, 2018
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. #!/bin/bash
  2. #usage: ./wav-ns.sh "content image" "comma,separated,style,images"
  3. CONTENT_IMAGE=$1
  4. STYLE_IMAGE=$2
  5. content=$(basename ${1%.*})
  6. style=$(basename ${2%.*})
  7. OUT_DIR="out/$content-$style/"
  8. mkdir -p $OUT_DIR
  9.  
  10. SCALE_DOWN=128
  11. SCALE_UP=1448
  12.  
  13. STYLE_WEIGHT=10000
  14. CONTENT_WEIGHT=100
  15.  
  16. WIDTH=`identify $CONTENT_IMAGE | cut -f 3 -d " " | sed s/x.*//`
  17. HEIGHT=`identify $CONTENT_IMAGE | cut -f 3 -d " " | sed s/.*x//`
  18. MIN=$(( WIDTH < HEIGHT ? WIDTH : HEIGHT ))
  19. MAX=$(( WIDTH > HEIGHT ? WIDTH : HEIGHT ))
  20. SCALE=$(( (1000 * 512 / $MIN) * $MIN / 1000))
  21.  
  22. python3 ../Neural-Tools/linear-color-transfer.py \
  23. --target_image $CONTENT_IMAGE \
  24. --source_image ${STYLE_IMAGE##*,} \
  25. --output_image $OUT_DIR/content-hist.png
  26.  
  27. convert $OUT_DIR/content-hist.png -resize ${SCALE}x${SCALE} $OUT_DIR/in.png
  28.  
  29. PREV=$OUT_DIR/in.png
  30.  
  31. th neural_style_multires.lua \
  32. -style_image $STYLE_IMAGE \
  33. -content_image $PREV \
  34. -output_image $OUT_DIR/$content-$style \
  35. -num_iterations 1000 \
  36. -optimizer lbfgs \
  37. -normalize_gradients \
  38. -style_scale 1 \
  39. -content_weight $(( $CONTENT_WEIGHT )) \
  40. -style_weight $(( $STYLE_WEIGHT )) \
  41. -image_size 1024 \
  42. -init image \
  43. -init_image $PREV \
  44. -overlap_times 2 \
  45. -scale_down $( echo $SCALE_DOWN/512 | bc -l ) \
  46. -scale_up $( echo $SCALE_DOWN/512 | bc -l ) \
  47. -scale_steps 1
  48.  
  49. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  50.  
  51. python3 ../Neural-Tools/linear-color-transfer.py \
  52. --target_image $PREV \
  53. --source_image ${STYLE_IMAGE##*,} \
  54. --output_image "${PREV%.*}"-hist.png
  55.  
  56. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  57.  
  58. for ((n=0;n<$(echo "($( echo "l(512) / l(2) - l($SCALE_DOWN) / l(2)" | bc -l ) + 0.5) / 1" | bc);n++)) do
  59. th neural_style_multires.lua \
  60. -style_image $STYLE_IMAGE \
  61. -content_image $PREV \
  62. -output_image $OUT_DIR/$content-$style \
  63. -num_iterations 800 \
  64. -optimizer lbfgs \
  65. -normalize_gradients \
  66. -style_scale 1 \
  67. -content_weight $CONTENT_WEIGHT \
  68. -style_weight $STYLE_WEIGHT \
  69. -image_size 1024 \
  70. -init image \
  71. -init_image $PREV \
  72. -overlap_times 2 \
  73. -scale_down 2 \
  74. -scale_up 2 \
  75. -scale_steps 1
  76.  
  77. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  78.  
  79. python3 ../Neural-Tools/linear-color-transfer.py \
  80. --target_image $PREV \
  81. --source_image ${STYLE_IMAGE##*,} \
  82. --output_image "${PREV%.*}"-hist.png
  83.  
  84. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  85. done
  86.  
  87. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  88.  
  89. python3 ../Neural-Tools/linear-color-transfer.py \
  90. --target_image $PREV \
  91. --source_image ${STYLE_IMAGE##*,} \
  92. --output_image "${PREV%.*}"-hist.png
  93.  
  94. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  95.  
  96. for ((n=-1;n<=$(echo "($( echo "l($SCALE_UP) / l( sqrt(2) ) - l(1024) / l( sqrt(2) )" | bc -l ) + 0.5) / 1" | bc);n++)) do
  97. th neural_style_multires.lua \
  98. -style_image $STYLE_IMAGE \
  99. -content_image $PREV \
  100. -output_image $OUT_DIR/$content-$style \
  101. -num_iterations 600 \
  102. -optimizer lbfgs \
  103. -normalize_gradients \
  104. -style_scale 1 \
  105. -content_weight $CONTENT_WEIGHT \
  106. -style_weight $STYLE_WEIGHT \
  107. -image_size 1024 \
  108. -init image \
  109. -init_image $PREV \
  110. -overlap_times 2 \
  111. -scale_down 1.414 \
  112. -scale_up 1.414 \
  113. -scale_steps 1
  114.  
  115. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  116.  
  117. python3 ../Neural-Tools/linear-color-transfer.py \
  118. --target_image $PREV \
  119. --source_image ${STYLE_IMAGE##*,} \
  120. --output_image "${PREV%.*}"-hist.png
  121.  
  122. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  123. done
  124.  
  125. STYLE_WEIGHT=1000
  126. STYLE_SCALE=1
  127. CONTENT_WEIGHT=0
  128.  
  129. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  130.  
  131. python3 ../Neural-Tools/linear-color-transfer.py \
  132. --target_image $PREV \
  133. --source_image ${STYLE_IMAGE##*,} \
  134. --output_image "${PREV%.*}"-hist.png
  135.  
  136. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  137.  
  138.  
  139. th neural_style.lua \
  140. -style_image $STYLE_IMAGE \
  141. -style_weight $STYLE_WEIGHT \
  142. -style_scale $STYLE_SCALE \
  143. -content_image $CONTENT_IMAGE \
  144. -content_weight $CONTENT_WEIGHT \
  145. -output_image $OUT_DIR/X4.png \
  146. -num_iterations 600 \
  147. -model_file models/channel_pruning.caffemodel \
  148. -proto_file models/channel_pruning.prototxt \
  149. -optimizer adam \
  150. -print_iter 300 \
  151. -tv_weight 0 \
  152. -backend cudnn \
  153. -init image \
  154. -init_image $PREV \
  155. -learning_rate 1 \
  156. -image_size 1600 \
  157. -original_colors 0 \
  158. -normalize_gradients
  159.  
  160.  
  161. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  162.  
  163. python3 ../Neural-Tools/linear-color-transfer.py \
  164. --target_image $PREV \
  165. --source_image ${STYLE_IMAGE##*,} \
  166. --output_image "${PREV%.*}"-hist.png
  167.  
  168. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  169.  
  170.  
  171. th neural_style.lua \
  172. -style_image $STYLE_IMAGE \
  173. -style_weight $STYLE_WEIGHT \
  174. -style_scale $STYLE_SCALE \
  175. -content_image $CONTENT_IMAGE \
  176. -content_weight $CONTENT_WEIGHT \
  177. -output_image $OUT_DIR/X5.png \
  178. -model_file models/nin_imagenet_conv.caffemodel \
  179. -proto_file models/train_val.prototxt \
  180. -num_iterations 200 \
  181. -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \
  182. -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \
  183. -optimizer adam \
  184. -print_iter 100 \
  185. -tv_weight 0 \
  186. -backend cudnn \
  187. -init image \
  188. -init_image $PREV \
  189. -learning_rate 1 \
  190. -image_size 2550 \
  191. -original_colors 0 \
  192. -normalize_gradients
  193.  
  194.  
  195. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  196.  
  197. python3 ../Neural-Tools/linear-color-transfer.py \
  198. --target_image $PREV \
  199. --source_image ${STYLE_IMAGE##*,} \
  200. --output_image "${PREV%.*}"-hist.png
  201.  
  202. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  203.  
  204. STYLE_WEIGHT=1000
  205. STYLE_SCALE=1
  206. CONTENT_WEIGHT=0
  207.  
  208.  
  209. th neural_style.lua \
  210. -style_image $STYLE_IMAGE \
  211. -style_weight $STYLE_WEIGHT \
  212. -style_scale $STYLE_SCALE \
  213. -content_image $CONTENT_IMAGE \
  214. -content_weight $CONTENT_WEIGHT \
  215. -output_image $OUT_DIR/X6.png \
  216. -model_file models/nin_imagenet_conv.caffemodel \
  217. -proto_file models/train_val.prototxt \
  218. -num_iterations 200 \
  219. -content_layers relu0,relu1,relu2,relu3,relu5,relu6 \
  220. -style_layers relu0,relu1,relu2,relu3,relu5,relu6 \
  221. -optimizer adam \
  222. -print_iter 100 \
  223. -tv_weight 0 \
  224. -backend cudnn \
  225. -init image \
  226. -init_image $PREV \
  227. -learning_rate 1 \
  228. -image_size 2700 \
  229. -original_colors 0 \
  230. -normalize_gradients
  231.  
  232.  
  233. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  234.  
  235. python3 ../Neural-Tools/linear-color-transfer.py \
  236. --target_image $PREV \
  237. --source_image ${STYLE_IMAGE##*,} \
  238. --output_image "${PREV%.*}"-hist.png
  239.  
  240. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  241.  
  242.  
  243. th neural_style.lua \
  244. -style_image $STYLE_IMAGE \
  245. -style_weight $STYLE_WEIGHT \
  246. -style_scale $STYLE_SCALE \
  247. -content_image $CONTENT_IMAGE \
  248. -content_weight $CONTENT_WEIGHT \
  249. -output_image $OUT_DIR/X7.png \
  250. -model_file models/nin_imagenet_conv.caffemodel \
  251. -proto_file models/train_val.prototxt \
  252. -num_iterations 200 \
  253. -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \
  254. -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \
  255. -optimizer adam \
  256. -print_iter 100 \
  257. -tv_weight 0 \
  258. -backend cudnn \
  259. -init image \
  260. -init_image $PREV \
  261. -learning_rate 1 \
  262. -image_size 2900 \
  263. -original_colors 0 \
  264. -normalize_gradients
  265.  
  266.  
  267. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  268.  
  269. python3 ../Neural-Tools/linear-color-transfer.py \
  270. --target_image $PREV \
  271. --source_image ${STYLE_IMAGE##*,} \
  272. --output_image "${PREV%.*}"-hist.png
  273.  
  274. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  275.  
  276.  
  277. th neural_style.lua \
  278. -style_image $STYLE_IMAGE \
  279. -style_weight $STYLE_WEIGHT \
  280. -style_scale $STYLE_SCALE \
  281. -content_image $CONTENT_IMAGE \
  282. -content_weight $CONTENT_WEIGHT \
  283. -output_image $OUT_DIR/X8.png \
  284. -model_file models/nin_imagenet_conv.caffemodel \
  285. -proto_file models/train_val.prototxt \
  286. -num_iterations 200 \
  287. -content_layers relu0,relu1 \
  288. -style_layers relu0,relu1 \
  289. -optimizer adam \
  290. -print_iter 100 \
  291. -tv_weight 0 \
  292. -backend cudnn \
  293. -init image \
  294. -init_image $PREV \
  295. -learning_rate 1 \
  296. -image_size 4000 \
  297. -original_colors 0 \
  298. -normalize_gradients
  299.  
  300.  
  301. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  302.  
  303. python3 ../Neural-Tools/linear-color-transfer.py \
  304. --target_image $PREV \
  305. --source_image ${STYLE_IMAGE##*,} \
  306. --output_image "${PREV%.*}"-hist.png
  307.  
  308. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  309.  
  310. STYLE_SCALE=0.5
  311.  
  312.  
  313. th neural_style.lua \
  314. -style_image $STYLE_IMAGE \
  315. -content_image $CONTENT_IMAGE \
  316. -output_image $OUT_DIR/$content-$style.png \
  317. -model_file models/nin_imagenet_conv.caffemodel \
  318. -proto_file models/train_val.prototxt \
  319. -num_iterations 20 \
  320. -content_layers relu0,relu1 \
  321. -style_layers relu0,relu1 \
  322. -optimizer adam \
  323. -print_iter 50 \
  324. -tv_weight 0 \
  325. -style_scale $STYLE_SCALE \
  326. -backend cudnn \
  327. -content_weight $CONTENT_WEIGHT \
  328. -style_weight $STYLE_WEIGHT \
  329. -init image \
  330. -init_image $PREV \
  331. -learning_rate 1 \
  332. -image_size 5000 \
  333. -original_colors 0
  334.  
  335.  
  336. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  337.  
  338. python3 ../Neural-Tools/linear-color-transfer.py \
  339. --target_image $PREV \
  340. --source_image ${STYLE_IMAGE##*,} \
  341. --output_image "${PREV%.*}"-hist.png
  342.  
  343. PREV=$OUT_DIR/$(ls -t $OUT_DIR | head -n1)
  344.  
  345.  
  346. python ../Neural-Tools/lum-transfer.py \
  347. --output_lum2 $PREV \
  348. --org_content $OUT_DIR/content-hist.png \
  349. --cp_mode lum2 \
  350. --output_image "${PREV%-hist.*}"-lum1.png
  351.  
  352. python ../Neural-Tools/lum-transfer.py \
  353. --output_lum2 $PREV \
  354. --org_content $CONTENT_IMAGE \
  355. --cp_mode lum2 \
  356. --output_image "${PREV%-hist.*}"-lum2.png
  357.  
  358. python ../Neural-Tools/lum-transfer.py \
  359. --output_lum2 $PREV \
  360. --org_content "$OUT_DIR/$content-$style-1024.png" \
  361. --cp_mode lum2 \
  362. --output_image "${PREV%-hist.*}"-match.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement