Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs, see PR or code comments #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion HRNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def forward(self, x):
residual = x
else:
residual = self.shortcut(x)
out += residual
# https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-torch-floattensor-64-1-which-is-output-0-of-asstridedbackward0-is-at-version-3-expected-version-2-instead-hint-the-backtrace-further-a/171826/7
out = out + residual
out = self.relu(out)

return out
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ this implementation is mainly based on [Deep Camouflage Images](http://zhangqing
- torchvision
- tqdm
- albumentations
- scikit-learn==0.23.2
- scikit-learn
- opencv-contrib
</details>

Expand Down Expand Up @@ -89,17 +89,17 @@ For custom images, you should prepare
```
- show_every : interval for displaying intermediate result
- save_process : If True, save intermediate result by every `show_every`
- show_comp : compressino ratio for display
- show_comp : compression ratio for display
```

## Influence by loss function
According to [Deep Camouflage Images](http://zhangqing-home.net/files/papers/2020/aaai2020.pdf), losses has following impact for generated image:

- style loss : control similarity between generated image and background image
- camouflage loss : control diffuculty for detection of camouflage objects in generated image
- camouflage loss : control difficulty for detection of camouflage objects in generated image
- leave loss : leave foreground features in generated image
- remove loss : remove foreground features in generated image
- reguralization loss : control consistency for generated image
- regularization loss : control consistency for generated image
- total variation loss : smooth generated image

|style|style+cam|
Expand Down
4 changes: 3 additions & 1 deletion camouflage_HRNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from sklearn.metrics.pairwise import cosine_distances,cosine_similarity
from sklearn.manifold import LocallyLinearEmbedding
from sklearn.neighbors import NearestNeighbors
from sklearn.manifold.locally_linear import barycenter_kneighbors_graph
# upgrade sklearn to latest version to avoid numpy type deprecation problem
# new version of sklearn requires to load barycenter_kneighbors_graph from sklearn.manifold._locally_linear
from sklearn.manifold._locally_linear import barycenter_kneighbors_graph

import HRNet
from hidden_recommend import recommend
Expand Down
2 changes: 1 addition & 1 deletion hidden_recommend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_MagGrad(gx, gy):
# Gradient histogram
def quantization(gradient):
# prepare quantization table
gradient_quantized = np.zeros_like(gradient, dtype=np.int)
gradient_quantized = np.zeros_like(gradient, dtype=int) # np.int is deprecated after 1.20

# quantization base
d = np.pi / 9
Expand Down
2 changes: 1 addition & 1 deletion params_Canyon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CFG:
########################
#### initial setting ###
########################
input_path="samples/inputs/kuma.png "
input_path="samples/inputs/kuma.png"
mask_path="samples/inputs/kuma_mask.png"
bg_path="samples/inputs/canyon.png"
output_dir="samples/outputs/HRNet/Canyon_kuma"
Expand Down
2 changes: 1 addition & 1 deletion params_Cliff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CFG:
########################
#### initial setting ###
########################
input_path="samples/inputs/kuma.png "
input_path="samples/inputs/kuma.png"
mask_path="samples/inputs/kuma_mask.png"
bg_path="samples/inputs/cliff.jpg"
output_dir="samples/outputs/HRNet/Cliff_kuma"
Expand Down
2 changes: 1 addition & 1 deletion params_CliffRiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CFG:
########################
#### initial setting ###
########################
input_path="samples/inputs/kuma.png "
input_path="samples/inputs/kuma.png"
mask_path="samples/inputs/kuma_mask.png"
bg_path="samples/inputs/cliff_river.png"
output_dir="samples/outputs/HRNet/CliffRiver_kuma"
Expand Down
2 changes: 1 addition & 1 deletion params_Mountain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CFG:
########################
#### initial setting ###
########################
input_path="samples/inputs/kuma.png "
input_path="samples/inputs/kuma.png"
mask_path="samples/inputs/kuma_mask.png"
bg_path="samples/inputs/mountain.jpg"
output_dir="samples/outputs/HRNet/Mountain_kuma"
Expand Down
2 changes: 1 addition & 1 deletion params_SeaMountain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CFG:
########################
#### initial setting ###
########################
input_path="samples/inputs/kuma.png "
input_path="samples/inputs/kuma.png"
mask_path="samples/inputs/kuma_mask.png"
bg_path="samples/inputs/sea_mountain.jpg"
output_dir="samples/outputs/HRNet/SeaMountain_kuma"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tqdm
albumentations
opencv-contrib-python
scikit-learn==0.23.2
scikit-learn