forked from DSE-MSU/DeepRobust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yaxin li
authored and
yaxin li
committed
Jul 29, 2020
1 parent
8dc5ab6
commit 83f7b99
Showing
185 changed files
with
53,139 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 8863c7c92ac5db6021935800e7f4e67f | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
282 changes: 282 additions & 0 deletions
282
docs/_build/html/_modules/deeprobust/graph/black_box.html
Large diffs are not rendered by default.
Oops, something went wrong.
423 changes: 423 additions & 0 deletions
423
docs/_build/html/_modules/deeprobust/graph/data/attacked_data.html
Large diffs are not rendered by default.
Oops, something went wrong.
437 changes: 437 additions & 0 deletions
437
docs/_build/html/_modules/deeprobust/graph/data/dataset.html
Large diffs are not rendered by default.
Oops, something went wrong.
264 changes: 264 additions & 0 deletions
264
docs/_build/html/_modules/deeprobust/graph/defense/adv_training.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
|
||
|
||
<!DOCTYPE html> | ||
<html class="writer-html5" lang="en" > | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>deeprobust.graph.defense.adv_training — DeepRobust 1.0 documentation</title> | ||
|
||
|
||
|
||
<link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" /> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!--[if lt IE 9]> | ||
<script src="../../../../_static/js/html5shiv.min.js"></script> | ||
<![endif]--> | ||
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script> | ||
<script src="../../../../_static/jquery.js"></script> | ||
<script src="../../../../_static/underscore.js"></script> | ||
<script src="../../../../_static/doctools.js"></script> | ||
<script src="../../../../_static/language_data.js"></script> | ||
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script> | ||
|
||
<script type="text/javascript" src="../../../../_static/js/theme.js"></script> | ||
|
||
|
||
<link rel="index" title="Index" href="../../../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../../../search.html" /> | ||
</head> | ||
|
||
<body class="wy-body-for-nav"> | ||
|
||
|
||
<div class="wy-grid-for-nav"> | ||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side"> | ||
<div class="wy-side-scroll"> | ||
<div class="wy-side-nav-search" > | ||
|
||
|
||
|
||
<a href="../../../../index.html" class="icon icon-home" alt="Documentation Home"> DeepRobust | ||
|
||
|
||
|
||
</a> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="search"> | ||
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get"> | ||
<input type="text" name="q" placeholder="Search docs" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="caption"><span class="caption-text">Image Package</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.image.attack.html">deeprobust.image.attack package</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.image.defense.html">deeprobust.image.defense package</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.image.netmodels.html">deeprobust.image.netmodels package</a></li> | ||
</ul> | ||
<p class="caption"><span class="caption-text">Graph Package</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.graph.global_attack.html">deeprobust.graph.global_attack package</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.graph.targeted_attack.html">deeprobust.graph.targeted_attack package</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../../source/deeprobust.graph.data.html">deeprobust.graph.data package</a></li> | ||
</ul> | ||
|
||
|
||
|
||
</div> | ||
|
||
</div> | ||
</nav> | ||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> | ||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation"> | ||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> | ||
<a href="../../../../index.html">DeepRobust</a> | ||
|
||
</nav> | ||
|
||
|
||
<div class="wy-nav-content"> | ||
|
||
<div class="rst-content"> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation"> | ||
|
||
<ul class="wy-breadcrumbs"> | ||
|
||
<li><a href="../../../../index.html" class="icon icon-home"></a> »</li> | ||
|
||
<li><a href="../../../index.html">Module code</a> »</li> | ||
|
||
<li>deeprobust.graph.defense.adv_training</li> | ||
|
||
|
||
<li class="wy-breadcrumbs-aside"> | ||
|
||
</li> | ||
|
||
</ul> | ||
|
||
|
||
<hr/> | ||
</div> | ||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> | ||
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for deeprobust.graph.defense.adv_training</h1><div class="highlight"><pre> | ||
<span></span><span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span> | ||
<span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">F</span> | ||
<span class="kn">import</span> <span class="nn">torch</span> | ||
<span class="kn">from</span> <span class="nn">torch.nn.modules.module</span> <span class="kn">import</span> <span class="n">Module</span> | ||
<span class="kn">from</span> <span class="nn">deeprobust.graph</span> <span class="kn">import</span> <span class="n">utils</span> | ||
<span class="kn">from</span> <span class="nn">deeprobust.graph.defense</span> <span class="kn">import</span> <span class="n">GCN</span> | ||
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span> | ||
<span class="kn">import</span> <span class="nn">scipy.sparse</span> <span class="k">as</span> <span class="nn">sp</span> | ||
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
|
||
|
||
<div class="viewcode-block" id="AdvTraining"><a class="viewcode-back" href="../../../../source/deeprobust.graph.defense.html#deeprobust.graph.defense.adv_training.AdvTraining">[docs]</a><span class="k">class</span> <span class="nc">AdvTraining</span><span class="p">:</span> | ||
<span class="sd">"""Adversarial training framework for defending against attacks.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> model :</span> | ||
<span class="sd"> model to protect, e.g, GCN</span> | ||
<span class="sd"> adversary :</span> | ||
<span class="sd"> attack model</span> | ||
<span class="sd"> device : str</span> | ||
<span class="sd"> 'cpu' or 'cuda'</span> | ||
<span class="sd"> """</span> | ||
|
||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">adversary</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="s1">'cpu'</span><span class="p">):</span> | ||
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">model</span> | ||
<span class="k">if</span> <span class="n">adversary</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> | ||
<span class="n">adversary</span> <span class="o">=</span> <span class="n">RND</span><span class="p">()</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">adversary</span> <span class="o">=</span> <span class="n">adversary</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">device</span> <span class="o">=</span> <span class="n">device</span> | ||
|
||
<div class="viewcode-block" id="AdvTraining.adv_train"><a class="viewcode-back" href="../../../../source/deeprobust.graph.defense.html#deeprobust.graph.defense.adv_training.AdvTraining.adv_train">[docs]</a> <span class="k">def</span> <span class="nf">adv_train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">features</span><span class="p">,</span> <span class="n">adj</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">idx_train</span><span class="p">,</span> <span class="n">train_iters</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | ||
<span class="sd">"""Start adversarial training.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> features :</span> | ||
<span class="sd"> node features</span> | ||
<span class="sd"> adj :</span> | ||
<span class="sd"> the adjacency matrix. The format could be torch.tensor or scipy matrix</span> | ||
<span class="sd"> labels :</span> | ||
<span class="sd"> node labels</span> | ||
<span class="sd"> idx_train :</span> | ||
<span class="sd"> node training indices</span> | ||
<span class="sd"> idx_val :</span> | ||
<span class="sd"> node validation indices. If not given (None), GCN training process will not adpot early stopping</span> | ||
<span class="sd"> train_iters : int</span> | ||
<span class="sd"> number of training epochs</span> | ||
<span class="sd"> """</span> | ||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">train_iters</span><span class="p">):</span> | ||
<span class="n">modified_adj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">adversary</span><span class="o">.</span><span class="n">attack</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">adj</span><span class="p">)</span> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">modified_adj</span><span class="p">,</span> <span class="n">train_iters</span><span class="p">,</span> <span class="n">initialize</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div></div> | ||
|
||
|
||
|
||
|
||
</pre></div> | ||
|
||
</div> | ||
|
||
</div> | ||
<footer> | ||
|
||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p> | ||
|
||
© Copyright | ||
|
||
</p> | ||
</div> | ||
|
||
|
||
|
||
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a | ||
|
||
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> | ||
|
||
provided by <a href="https://readthedocs.org">Read the Docs</a>. | ||
|
||
</footer> | ||
|
||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
|
||
<script type="text/javascript"> | ||
jQuery(function () { | ||
SphinxRtdTheme.Navigation.enable(true); | ||
}); | ||
</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Oops, something went wrong.