varidock 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- varidock-0.1.0/LICENSE +21 -0
- varidock-0.1.0/PKG-INFO +33 -0
- varidock-0.1.0/README.md +20 -0
- varidock-0.1.0/pyproject.toml +29 -0
- varidock-0.1.0/setup.cfg +4 -0
- varidock-0.1.0/setup.py +5 -0
- varidock-0.1.0/varidock/__init__.py +0 -0
- varidock-0.1.0/varidock/broker/__init__.py +0 -0
- varidock-0.1.0/varidock/broker/adfr/__init__.py +3 -0
- varidock-0.1.0/varidock/broker/adfr/prepare_receptor.py +118 -0
- varidock-0.1.0/varidock/broker/deepsurf/__init__.py +3 -0
- varidock-0.1.0/varidock/broker/deepsurf/bsite_extraction.py +55 -0
- varidock-0.1.0/varidock/broker/deepsurf/features.py +37 -0
- varidock-0.1.0/varidock/broker/deepsurf/net/__init__.py +0 -0
- varidock-0.1.0/varidock/broker/deepsurf/net/resnet_3d.py +180 -0
- varidock-0.1.0/varidock/broker/deepsurf/net/resnet_3d_utils.py +295 -0
- varidock-0.1.0/varidock/broker/deepsurf/net/resnet_lds_3d_bottleneck.py +173 -0
- varidock-0.1.0/varidock/broker/deepsurf/network.py +76 -0
- varidock-0.1.0/varidock/broker/deepsurf/old.predict.py +51 -0
- varidock-0.1.0/varidock/broker/deepsurf/predict.py +41 -0
- varidock-0.1.0/varidock/broker/deepsurf/protein.py +94 -0
- varidock-0.1.0/varidock/broker/deepsurf/tfbio_data.py +530 -0
- varidock-0.1.0/varidock/broker/deepsurf/utils.py +122 -0
- varidock-0.1.0/varidock/broker/meeko/__init__.py +3 -0
- varidock-0.1.0/varidock/broker/meeko/meeko.py +48 -0
- varidock-0.1.0/varidock/broker/vina/__init__.py +3 -0
- varidock-0.1.0/varidock/broker/vina/vina.py +44 -0
- varidock-0.1.0/varidock/cli.py +89 -0
- varidock-0.1.0/varidock/config.py +77 -0
- varidock-0.1.0/varidock/execution/__init__.py +15 -0
- varidock-0.1.0/varidock/execution/local.py +43 -0
- varidock-0.1.0/varidock/execution/materialize.py +27 -0
- varidock-0.1.0/varidock/execution/run.py +49 -0
- varidock-0.1.0/varidock/execution/slurm.py +14 -0
- varidock-0.1.0/varidock/execution/utils.py +17 -0
- varidock-0.1.0/varidock/execution/validate.py +19 -0
- varidock-0.1.0/varidock/io/__init__.py +3 -0
- varidock-0.1.0/varidock/io/af3_json.py +48 -0
- varidock-0.1.0/varidock/io/af3_load.py +37 -0
- varidock-0.1.0/varidock/io/boltz_yaml.py +53 -0
- varidock-0.1.0/varidock/io/fasta.py +8 -0
- varidock-0.1.0/varidock/jobs/__init__.py +3 -0
- varidock-0.1.0/varidock/jobs/jobs.py +57 -0
- varidock-0.1.0/varidock/pipeline/__init__.py +35 -0
- varidock-0.1.0/varidock/pipeline/pipeline.py +24 -0
- varidock-0.1.0/varidock/pipeline/stage.py +12 -0
- varidock-0.1.0/varidock/pipeline/types.py +112 -0
- varidock-0.1.0/varidock/plans.py +30 -0
- varidock-0.1.0/varidock/runners/__init__.py +11 -0
- varidock-0.1.0/varidock/runners/af3.py +109 -0
- varidock-0.1.0/varidock/runners/base.py +21 -0
- varidock-0.1.0/varidock/runners/boltz.py +84 -0
- varidock-0.1.0/varidock/stages/__init__.py +0 -0
- varidock-0.1.0/varidock/stages/adfr_protein_receptor_prep.py +50 -0
- varidock-0.1.0/varidock/stages/af3_single_protein_predictor.py +67 -0
- varidock-0.1.0/varidock/stages/center_ligand_to_pocket.py +89 -0
- varidock-0.1.0/varidock/stages/cif_to_pdb.py +40 -0
- varidock-0.1.0/varidock/stages/deepsurf_pockets.py +61 -0
- varidock-0.1.0/varidock/stages/insert_plddt_to_pdb.py +92 -0
- varidock-0.1.0/varidock/stages/meeko_ligand_prep.py +51 -0
- varidock-0.1.0/varidock/stages/namd_eq.py +54 -0
- varidock-0.1.0/varidock/stages/namd_eq2.py +56 -0
- varidock-0.1.0/varidock/stages/namd_prod.py +59 -0
- varidock-0.1.0/varidock/stages/vina_dock.py +119 -0
- varidock-0.1.0/varidock/stages/vmd_equil_prep.py +144 -0
- varidock-0.1.0/varidock/stages/vmd_frame_extract.py +75 -0
- varidock-0.1.0/varidock/structure/__init__.py +5 -0
- varidock-0.1.0/varidock/structure/base.py +31 -0
- varidock-0.1.0/varidock/structure/msa.py +22 -0
- varidock-0.1.0/varidock/structure/template.py +12 -0
- varidock-0.1.0/varidock.egg-info/PKG-INFO +33 -0
- varidock-0.1.0/varidock.egg-info/SOURCES.txt +74 -0
- varidock-0.1.0/varidock.egg-info/dependency_links.txt +1 -0
- varidock-0.1.0/varidock.egg-info/entry_points.txt +2 -0
- varidock-0.1.0/varidock.egg-info/requires.txt +3 -0
- varidock-0.1.0/varidock.egg-info/top_level.txt +1 -0
varidock-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abdolla Hegazy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
varidock-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: varidock
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Docker Automation
|
|
5
|
+
Author-email: Abdolla Hegazy <hegazyab@msu.edu>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# pypi-template
|
|
15
|
+
|
|
16
|
+
[](https://lonelyneutrin0.github.io/pypi-template/)
|
|
17
|
+
[](https://pypi.python.org/pypi/pypi-template/)
|
|
18
|
+
[](https://pypi.python.org/pypi/pypi-template/)
|
|
19
|
+
|
|
20
|
+
## About pypi-template
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
`pypi-template` is published on [PyPi](https://pypi.python.org/pypi/pypi-template/) and can be installed using `pip` -
|
|
24
|
+
```
|
|
25
|
+
pip install pypi-template
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
`pypi-template` is available under the MIT License.
|
|
30
|
+
|
|
31
|
+
## Attribution
|
|
32
|
+
|
|
33
|
+
## Contributing
|
varidock-0.1.0/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# pypi-template
|
|
2
|
+
|
|
3
|
+
[](https://lonelyneutrin0.github.io/pypi-template/)
|
|
4
|
+
[](https://pypi.python.org/pypi/pypi-template/)
|
|
5
|
+
[](https://pypi.python.org/pypi/pypi-template/)
|
|
6
|
+
|
|
7
|
+
## About pypi-template
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
`pypi-template` is published on [PyPi](https://pypi.python.org/pypi/pypi-template/) and can be installed using `pip` -
|
|
11
|
+
```
|
|
12
|
+
pip install pypi-template
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
`pypi-template` is available under the MIT License.
|
|
17
|
+
|
|
18
|
+
## Attribution
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "varidock"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Docker Automation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
|
|
13
|
+
authors = [{ name = "Abdolla Hegazy", email = "hegazyab@msu.edu" }]
|
|
14
|
+
|
|
15
|
+
dependencies = []
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
dev = [
|
|
19
|
+
"pytest>=8",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["varidock"]
|
|
24
|
+
|
|
25
|
+
[tool.pytest.ini_options]
|
|
26
|
+
testpaths = ["tests"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
varidock = "varidock.cli:cli"
|
varidock-0.1.0/setup.cfg
ADDED
varidock-0.1.0/setup.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from MolKit import Read
|
|
4
|
+
from AutoDockTools.MoleculePreparation import AD4ReceptorPreparation
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def prepare_receptor(
|
|
8
|
+
receptor_filename: str,
|
|
9
|
+
verbose: bool = False,
|
|
10
|
+
outputfilename: str | None = None,
|
|
11
|
+
repairs: str = "",
|
|
12
|
+
charges_to_add: str | None = "gasteiger",
|
|
13
|
+
preserve_charge_types: str | None = None,
|
|
14
|
+
cleanup: str = "nphs_lps_waters_nonstdres",
|
|
15
|
+
mode: str = "automatic",
|
|
16
|
+
delete_single_nonstd_residues: bool = False,
|
|
17
|
+
dictionary: str | None = None,
|
|
18
|
+
unique_atom_names: bool = False,
|
|
19
|
+
):
|
|
20
|
+
"""Prepare a receptor PDB/MOL2 file for AutoDock4 docking (produces PDBQT)."""
|
|
21
|
+
if not receptor_filename:
|
|
22
|
+
raise ValueError("receptor filename must be specified.")
|
|
23
|
+
|
|
24
|
+
mols = Read(receptor_filename)
|
|
25
|
+
if verbose:
|
|
26
|
+
print("read ", receptor_filename)
|
|
27
|
+
mol = mols[0]
|
|
28
|
+
|
|
29
|
+
if unique_atom_names:
|
|
30
|
+
for at in mol.allAtoms:
|
|
31
|
+
if mol.allAtoms.get(at.name) > 1:
|
|
32
|
+
at.name = at.name + str(at._uniqIndex + 1)
|
|
33
|
+
if verbose:
|
|
34
|
+
print(
|
|
35
|
+
"renamed %d atoms: each newname is the original name of the atom plus its (1-based) uniqIndex"
|
|
36
|
+
% len(mol.allAtoms)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
preserved = {}
|
|
40
|
+
has_autodock_element = False
|
|
41
|
+
if charges_to_add and preserve_charge_types:
|
|
42
|
+
if hasattr(mol, "allAtoms") and not hasattr(
|
|
43
|
+
mol.allAtoms[0], "autodock_element"
|
|
44
|
+
):
|
|
45
|
+
file_name, file_ext = os.path.splitext(receptor_filename)
|
|
46
|
+
if file_ext == ".pdbqt":
|
|
47
|
+
has_autodock_element = True
|
|
48
|
+
if preserve_charge_types and not has_autodock_element:
|
|
49
|
+
raise RuntimeError(
|
|
50
|
+
"input format does not have autodock_element SO unable to preserve charges on "
|
|
51
|
+
+ preserve_charge_types
|
|
52
|
+
)
|
|
53
|
+
preserved_types = preserve_charge_types.split(",")
|
|
54
|
+
if verbose:
|
|
55
|
+
print("preserved_types=", preserved_types)
|
|
56
|
+
for t in preserved_types:
|
|
57
|
+
if verbose:
|
|
58
|
+
print("preserving charges on type->", t)
|
|
59
|
+
if not len(t):
|
|
60
|
+
continue
|
|
61
|
+
ats = mol.allAtoms.get(lambda x: x.autodock_element == t)
|
|
62
|
+
if verbose:
|
|
63
|
+
print("preserving charges on ", ats.name)
|
|
64
|
+
for a in ats:
|
|
65
|
+
if a.chargeSet is not None:
|
|
66
|
+
preserved[a] = [a.chargeSet, a.charge]
|
|
67
|
+
|
|
68
|
+
if len(mols) > 1:
|
|
69
|
+
if verbose:
|
|
70
|
+
print("more than one molecule in file")
|
|
71
|
+
ctr = 1
|
|
72
|
+
for m in mols[1:]:
|
|
73
|
+
ctr += 1
|
|
74
|
+
if len(m.allAtoms) > len(mol.allAtoms):
|
|
75
|
+
mol = m
|
|
76
|
+
if verbose:
|
|
77
|
+
print(
|
|
78
|
+
"mol set to ",
|
|
79
|
+
ctr,
|
|
80
|
+
"th molecule with",
|
|
81
|
+
len(mol.allAtoms),
|
|
82
|
+
"atoms",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
mol.buildBondsByDistance()
|
|
86
|
+
alt_loc_ats = mol.allAtoms.get(lambda x: "@" in x.name)
|
|
87
|
+
len_alt_loc_ats = len(alt_loc_ats)
|
|
88
|
+
if len_alt_loc_ats:
|
|
89
|
+
print(
|
|
90
|
+
"WARNING!",
|
|
91
|
+
mol.name,
|
|
92
|
+
"has",
|
|
93
|
+
len_alt_loc_ats,
|
|
94
|
+
" alternate location atoms!\nUse prepare_pdb_split_alt_confs.py to create pdb files containing a single conformation.\n",
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
if verbose:
|
|
98
|
+
print("setting up RPO with mode=", mode, end=" ")
|
|
99
|
+
print("and outputfilename= ", outputfilename)
|
|
100
|
+
print("charges_to_add=", charges_to_add)
|
|
101
|
+
print("delete_single_nonstd_residues=", delete_single_nonstd_residues)
|
|
102
|
+
|
|
103
|
+
RPO = AD4ReceptorPreparation( # noqa: F841
|
|
104
|
+
mol,
|
|
105
|
+
mode,
|
|
106
|
+
repairs,
|
|
107
|
+
charges_to_add,
|
|
108
|
+
cleanup,
|
|
109
|
+
outputfilename=outputfilename,
|
|
110
|
+
preserved=preserved,
|
|
111
|
+
delete_single_nonstd_residues=delete_single_nonstd_residues,
|
|
112
|
+
dict=dictionary,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if charges_to_add:
|
|
116
|
+
for atom, chargeList in list(preserved.items()):
|
|
117
|
+
atom._charges[chargeList[0]] = chargeList[1]
|
|
118
|
+
atom.chargeSet = chargeList[0]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env python2
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Thu Jan 30 16:00:46 2020
|
|
5
|
+
|
|
6
|
+
@author: smylonas
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from sklearn.cluster import MeanShift
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Bsite_extractor():
|
|
14
|
+
def __init__(self,lig_thres,bw=15):
|
|
15
|
+
self.T = lig_thres
|
|
16
|
+
self.ms = MeanShift(bandwidth=bw,bin_seeding=True,cluster_all=False,n_jobs=4)
|
|
17
|
+
|
|
18
|
+
def _cluster_points(self,prot,lig_scores):
|
|
19
|
+
T_new = self.T
|
|
20
|
+
while sum(lig_scores>=T_new) < 10 and T_new>0.3001: # at least 10 points with prob>P and P>=0.3
|
|
21
|
+
T_new -= 0.1
|
|
22
|
+
|
|
23
|
+
filtered_points = prot.surf_points[lig_scores>T_new]
|
|
24
|
+
filtered_scores = lig_scores[lig_scores>T_new]
|
|
25
|
+
if len(filtered_points)<5:
|
|
26
|
+
return ()
|
|
27
|
+
|
|
28
|
+
clustering = self.ms.fit(filtered_points)
|
|
29
|
+
labels = clustering.labels_
|
|
30
|
+
|
|
31
|
+
unique_l,freq = np.unique(labels,return_counts=True)
|
|
32
|
+
|
|
33
|
+
if len(unique_l[freq>=5])!=0:
|
|
34
|
+
unique_l = unique_l[freq>=5] # keep clusters with 5 points and more
|
|
35
|
+
else:
|
|
36
|
+
return ()
|
|
37
|
+
|
|
38
|
+
if unique_l[0]==-1: # discard the "unclustered" cluster
|
|
39
|
+
unique_l = unique_l[1:]
|
|
40
|
+
|
|
41
|
+
clusters = [(filtered_points[labels==l],filtered_scores[labels==l]) for l in unique_l] # noqa: E741
|
|
42
|
+
|
|
43
|
+
return clusters
|
|
44
|
+
|
|
45
|
+
def extract_bsites(self,prot,lig_scores):
|
|
46
|
+
clusters = self._cluster_points(prot,lig_scores)
|
|
47
|
+
if len(clusters)==0:
|
|
48
|
+
print('No binding site found')
|
|
49
|
+
return
|
|
50
|
+
for cluster in clusters:
|
|
51
|
+
prot.add_bsite(cluster)
|
|
52
|
+
prot.sort_bsites()
|
|
53
|
+
prot.write_bsites()
|
|
54
|
+
|
|
55
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env python2
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Mon Oct 21 11:46:54 2019
|
|
5
|
+
|
|
6
|
+
@author: smylonas
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from .tfbio_data import Featurizer,make_grid
|
|
11
|
+
from .utils import rotation
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class KalasantyFeaturizer:
|
|
16
|
+
def __init__(self,gridSize,voxelSize):
|
|
17
|
+
grid_limit = (gridSize/2-0.5)*voxelSize
|
|
18
|
+
grid_radius = grid_limit*np.sqrt(3)
|
|
19
|
+
self.neigh_radius = 4 + grid_radius # 4 > 2*R_vdw
|
|
20
|
+
self.featurizer = Featurizer(save_molecule_codes=False)
|
|
21
|
+
self.grid_resolution = voxelSize
|
|
22
|
+
self.max_dist = (gridSize-1)*voxelSize/2
|
|
23
|
+
|
|
24
|
+
def get_channels(self,mol):
|
|
25
|
+
_, self.channels = self.featurizer.get_features(mol) # returns only heavy atoms
|
|
26
|
+
|
|
27
|
+
def grid_feats(self,point,normal,mol_coords):
|
|
28
|
+
neigh_atoms = np.sqrt(np.sum((mol_coords-point)**2,axis=1))<self.neigh_radius
|
|
29
|
+
Q = rotation(normal)
|
|
30
|
+
Q_inv = np.linalg.inv(Q)
|
|
31
|
+
transf_coords = np.transpose(mol_coords[neigh_atoms]-point)
|
|
32
|
+
rotated_mol_coords = np.matmul(Q_inv,transf_coords)
|
|
33
|
+
features = make_grid(np.transpose(rotated_mol_coords),self.channels[neigh_atoms],self.grid_resolution,self.max_dist)[0]
|
|
34
|
+
|
|
35
|
+
return features
|
|
36
|
+
|
|
37
|
+
|
|
File without changes
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Created on Thu Nov 1 12:04:04 2018
|
|
3
|
+
|
|
4
|
+
@author: smylonas
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import tensorflow as tf
|
|
8
|
+
from tf_slim import layers
|
|
9
|
+
from tf_slim import add_arg_scope,arg_scope
|
|
10
|
+
from tf_slim.layers import utils
|
|
11
|
+
from tensorflow.python.ops import math_ops
|
|
12
|
+
from tensorflow.python.ops import nn_ops
|
|
13
|
+
from tensorflow.python.ops import variable_scope
|
|
14
|
+
from . import resnet_3d_utils
|
|
15
|
+
|
|
16
|
+
resnet_arg_scope = resnet_3d_utils.resnet_arg_scope
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@add_arg_scope
|
|
20
|
+
def resid_unit(inputs,
|
|
21
|
+
depth,
|
|
22
|
+
depth_bottleneck,
|
|
23
|
+
stride,
|
|
24
|
+
rate=1,
|
|
25
|
+
outputs_collections=None,
|
|
26
|
+
scope=None):
|
|
27
|
+
"""Residual unit with BN after convolutions.
|
|
28
|
+
This is the original residual unit proposed in [1]. See Fig. 1(a) of [2] for
|
|
29
|
+
its definition.
|
|
30
|
+
When putting together two consecutive ResNet blocks that use this unit, one
|
|
31
|
+
should use stride = 2 in the last unit of the first block.
|
|
32
|
+
Args:
|
|
33
|
+
inputs: A tensor of size [batch, height, width, channels].
|
|
34
|
+
depth: The depth of the ResNet unit output.
|
|
35
|
+
depth_bottleneck: The depth of the bottleneck layers.
|
|
36
|
+
stride: The ResNet unit's stride. Determines the amount of downsampling of
|
|
37
|
+
the units output compared to its input.
|
|
38
|
+
rate: An integer, rate for atrous convolution.
|
|
39
|
+
outputs_collections: Collection to add the ResNet unit output.
|
|
40
|
+
scope: Optional variable_scope.
|
|
41
|
+
Returns:
|
|
42
|
+
The ResNet unit's output.
|
|
43
|
+
"""
|
|
44
|
+
with variable_scope.variable_scope(scope, 'resid_v1', [inputs]) as sc:
|
|
45
|
+
# print (inputs.shape)
|
|
46
|
+
depth_in = utils.last_dimension(inputs.get_shape(), min_rank=5)
|
|
47
|
+
if depth == depth_in:
|
|
48
|
+
shortcut = resnet_3d_utils.subsample(inputs, stride, 'shortcut')
|
|
49
|
+
else:
|
|
50
|
+
shortcut = layers.conv3d(
|
|
51
|
+
inputs,
|
|
52
|
+
depth, [1, 1, 1],
|
|
53
|
+
stride=stride,
|
|
54
|
+
activation_fn=None,
|
|
55
|
+
scope='shortcut')
|
|
56
|
+
|
|
57
|
+
residual = resnet_3d_utils.conv3d_same(inputs, depth_bottleneck, 3, stride=1, scope='conv1')
|
|
58
|
+
residual = layers.conv3d(residual, depth_bottleneck, 3, stride, scope='conv2')
|
|
59
|
+
|
|
60
|
+
output = nn_ops.relu(shortcut + residual)
|
|
61
|
+
|
|
62
|
+
return utils.collect_named_outputs(outputs_collections, sc.name, output)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def resnet_v1(inputs,
|
|
66
|
+
blocks,
|
|
67
|
+
num_classes=None,
|
|
68
|
+
is_training=True,
|
|
69
|
+
global_pool=True,
|
|
70
|
+
output_stride=None,
|
|
71
|
+
include_root_block=True,
|
|
72
|
+
reuse=None,
|
|
73
|
+
scope=None):
|
|
74
|
+
"""Generator for v1 ResNet models.
|
|
75
|
+
Args:
|
|
76
|
+
inputs: A tensor of size [batch, height_in, width_in, channels].
|
|
77
|
+
blocks: A list of length equal to the number of ResNet blocks. Each element
|
|
78
|
+
is a resnet_utils.Block object describing the units in the block.
|
|
79
|
+
num_classes: Number of predicted classes for classification tasks. If None
|
|
80
|
+
we return the features before the logit layer.
|
|
81
|
+
is_training: whether batch_norm layers are in training mode.
|
|
82
|
+
global_pool: If True, we perform global average pooling before computing the
|
|
83
|
+
logits. Set to True for image classification, False for dense prediction.
|
|
84
|
+
output_stride: If None, then the output will be computed at the nominal
|
|
85
|
+
network stride. If output_stride is not None, it specifies the requested
|
|
86
|
+
ratio of input to output spatial resolution.
|
|
87
|
+
include_root_block: If True, include the initial convolution followed by
|
|
88
|
+
max-pooling, if False excludes it.
|
|
89
|
+
reuse: whether or not the network and its variables should be reused. To be
|
|
90
|
+
able to reuse 'scope' must be given.
|
|
91
|
+
scope: Optional variable_scope.
|
|
92
|
+
Returns:
|
|
93
|
+
net: A rank-4 tensor of size [batch, height_out, width_out, channels_out].
|
|
94
|
+
If global_pool is False, then height_out and width_out are reduced by a
|
|
95
|
+
factor of output_stride compared to the respective height_in and width_in,
|
|
96
|
+
else both height_out and width_out equal one. If num_classes is None, then
|
|
97
|
+
net is the output of the last ResNet block, potentially after global
|
|
98
|
+
average pooling. If num_classes is not None, net contains the pre-softmax
|
|
99
|
+
activations.
|
|
100
|
+
end_points: A dictionary from components of the network to the corresponding
|
|
101
|
+
activation.
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If the target output_stride is not valid.
|
|
104
|
+
"""
|
|
105
|
+
with variable_scope.variable_scope(
|
|
106
|
+
scope, 'resnet_v1', [inputs], reuse=reuse) as sc:
|
|
107
|
+
end_points_collection = sc.original_name_scope + '_end_points'
|
|
108
|
+
with arg_scope(
|
|
109
|
+
[layers.conv3d, resid_unit, resnet_3d_utils.stack_blocks_dense],
|
|
110
|
+
outputs_collections=end_points_collection):
|
|
111
|
+
with arg_scope([layers.batch_norm], is_training=is_training):
|
|
112
|
+
net = inputs
|
|
113
|
+
net = resnet_3d_utils.stack_blocks_dense(net, blocks, output_stride)
|
|
114
|
+
if global_pool:
|
|
115
|
+
net = math_ops.reduce_mean(net, [1, 2, 3], name='pool5', keepdims=True)
|
|
116
|
+
if num_classes is not None:
|
|
117
|
+
net = layers.conv3d(
|
|
118
|
+
net,
|
|
119
|
+
num_classes, [1, 1, 1],
|
|
120
|
+
activation_fn=None,
|
|
121
|
+
normalizer_fn=None,
|
|
122
|
+
scope='logits')
|
|
123
|
+
|
|
124
|
+
# Convert end_points_collection into a dictionary of end_points.
|
|
125
|
+
end_points = utils.convert_collection_to_dict(end_points_collection)
|
|
126
|
+
if num_classes is not None and num_classes != 1:
|
|
127
|
+
end_points['predictions'] = layers.softmax(net, scope='predictions')
|
|
128
|
+
net = tf.squeeze(net)
|
|
129
|
+
elif num_classes == 1:
|
|
130
|
+
net = tf.squeeze(net)
|
|
131
|
+
end_points['probs'] = tf.nn.sigmoid(net)
|
|
132
|
+
|
|
133
|
+
return net, end_points
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def resnet_v1_block(scope, depth_out, num_units, stride):
|
|
137
|
+
"""Args:
|
|
138
|
+
scope: The scope of the block.
|
|
139
|
+
base_depth: The depth of the bottleneck layer for each unit.
|
|
140
|
+
num_units: The number of units in the block.
|
|
141
|
+
stride: The stride of the block, implemented as a stride in the last unit.
|
|
142
|
+
All other units have stride=1.
|
|
143
|
+
Returns:
|
|
144
|
+
A resnet_v1 bottleneck block.
|
|
145
|
+
"""
|
|
146
|
+
return resnet_3d_utils.Block(scope, resid_unit, [{
|
|
147
|
+
'depth': depth_out,
|
|
148
|
+
'depth_bottleneck': depth_out,
|
|
149
|
+
'stride': 1
|
|
150
|
+
}] * (num_units - 1) + [{
|
|
151
|
+
'depth': depth_out,
|
|
152
|
+
'depth_bottleneck': depth_out,
|
|
153
|
+
'stride': stride
|
|
154
|
+
}])
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def resnet_v1_18(inputs,
|
|
158
|
+
num_classes,
|
|
159
|
+
is_training,
|
|
160
|
+
global_pool=True,
|
|
161
|
+
output_stride=None,
|
|
162
|
+
reuse=None,
|
|
163
|
+
scope='resnet3d_v1_18'):
|
|
164
|
+
blocks = [
|
|
165
|
+
resnet_v1_block('block1', depth_out=64, num_units=2, stride=2),
|
|
166
|
+
resnet_v1_block('block2', depth_out=128, num_units=2, stride=2),
|
|
167
|
+
resnet_v1_block('block3', depth_out=256, num_units=2, stride=2),
|
|
168
|
+
resnet_v1_block('block4', depth_out=512, num_units=2, stride=1)
|
|
169
|
+
]
|
|
170
|
+
return resnet_v1(
|
|
171
|
+
inputs,
|
|
172
|
+
blocks,
|
|
173
|
+
num_classes,
|
|
174
|
+
is_training,
|
|
175
|
+
global_pool,
|
|
176
|
+
output_stride,
|
|
177
|
+
include_root_block=False,
|
|
178
|
+
reuse=reuse,
|
|
179
|
+
scope=scope)
|
|
180
|
+
|