Skip to content

Commit

Permalink
enhanced mask convertion part - use Paint to resize-much better
Browse files Browse the repository at this point in the history
  • Loading branch information
lcipolina committed Apr 19, 2022
1 parent bae1a20 commit fdb2b11
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions ML/Colab-co-mod-gan.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"id": "WGyKCHF53NjW"
},
"source": [
"'''\n",
"\n",
"#@title (optional) read / write / resize file with opencv / invert mask\n",
"#@markdown You need masks where ``white = original`` and ``black = inpaint``. Both images are rgb and have the needed dimensions.\n",
"import cv2\n",
Expand All @@ -119,12 +119,28 @@
"image = cv2.imread(path_mask)\n",
"image = 255-image\n",
"image = cv2.resize(image, (512,512), cv2.INTER_NEAREST)\n",
"cv2.imwrite(path_mask, image)\n",
"'''"
"cv2.imwrite(path_mask, image)\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# ***** mask color inversion ***************************************************************************\n",
"# The part of the image that has to be predicted by the model should be in black and the rest in white\n",
"# The code above inverts the colors of the mask!\n",
"src = '/content/'\n",
"#convert mask\n",
"img = cv2.imread(src + 'input.png') # bitwise function needs img as array # use previously saved name \n",
"cv2.imwrite(src + 'mask.png', cv2.bitwise_not(img)) #operations are not done -in place - we need to go back from array to image"
],
"metadata": {
"id": "1DLPl1lCsyOn"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
Expand Down Expand Up @@ -181,8 +197,11 @@
{
"cell_type": "code",
"source": [
"# Run the model\n",
"# change name of input and mask files\n",
"\n",
"%cd /content/co-mod-gan\n",
"!python run_generator.py -c /content/co-mod-gan/co-mod-gan-places2-050000.pkl -i /content/co-mod-gan/imgs/7.jpg -m /content/co-mod-gan/imgs/mask6.png -o /content/output.png\n",
"!python run_generator.py -c /content/co-mod-gan/co-mod-gan-places2-050000.pkl -i /content/input.png -m /content/mask.png -o /content/output.png\n",
"\n",
"print('DONE')\n",
"\n",
Expand Down

0 comments on commit fdb2b11

Please sign in to comment.