Tube segmentationΒΆ

[1]:
from brainlit.utils import session
from brainlit.feature_extraction import *
import napari
/opt/buildhome/python3.7/lib/python3.7/site-packages/python_jsonschema_objects/__init__.py:53: UserWarning: Schema version http://json-schema.org/draft-04/schema not recognized. Some keywords and features may not be supported.
  self.schema["$schema"]
[2]:
url = "s3://open-neurodata/brainlit/brain1"
sess = session.NeuroglancerSession(url=url, url_segments=url+"_segments", mip=0)
SEGLIST=[101,103,106,107,109,11,111,112,115,11,12,120,124,126,127,129,13,132,133,136,137,14,140,141,142,143,144,145,146,147,149,150]
SEGLIST = SEGLIST[:1]
[3]:
# %%capture
nbr = NeighborhoodFeatures(url=url, radius=1, offset=[50,50,50], segment_url=url+"_segments")
nbr.fit(seg_ids=SEGLIST, num_verts=10, file_path='demo', batch_size=10)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-1-55b8d0467f4f> in <module>
      1 # %%capture
      2 nbr = NeighborhoodFeatures(url=url, radius=1, offset=[50,50,50], segment_url=url+"_segments")
----> 3 nbr.fit(seg_ids=SEGLIST, num_verts=10, file_path='demo', batch_size=10)

/opt/build/repo/brainlit/feature_extraction/base.py in fit(self, seg_ids, num_verts, file_path, batch_size, start_seg, start_vert, include_neighborhood, n_jobs)
    145                     True,
    146                     batch_size,
--> 147                     file_path,
    148                 )
    149             else:

/opt/build/repo/brainlit/feature_extraction/base.py in _serial_processing(self, seg_ids, ngl, num_verts, start_vert, include_neighborhood, write, batch_size, file_path)
    185                 segment = ngl.cv.skeleton.get(seg_id)
    186             else:
--> 187                 cv_skel = CloudVolume(self.segment_url, use_https=True)
    188                 segment = cv_skel.skeleton.get(seg_id)
    189             if num_verts is not None and num_verts <= len(segment.vertices):

~/python3.7/lib/python3.7/site-packages/cloudvolume/cloudvolume.py in __new__(cls, cloudpath, mip, bounded, autocrop, fill_missing, cache, compress_cache, cdn_cache, progress, info, provenance, compress, compress_level, non_aligned_writes, parallel, delete_black_uploads, background_color, green_threads, use_https, max_redirects)
    195     path = strict_extract(cloudpath)
    196     if path.format in REGISTERED_PLUGINS:
--> 197       return REGISTERED_PLUGINS[path.format](**kwargs)
    198     else:
    199       raise UnsupportedFormatError(

~/python3.7/lib/python3.7/site-packages/cloudvolume/datasource/precomputed/__init__.py in create_precomputed(cloudpath, mip, bounded, autocrop, fill_missing, cache, compress_cache, cdn_cache, progress, info, provenance, compress, compress_level, non_aligned_writes, parallel, delete_black_uploads, background_color, green_threads, use_https, max_redirects)
     40       cloudpath, cache=cache,
     41       info=info, provenance=provenance,
---> 42       max_redirects=max_redirects
     43     )
     44

~/python3.7/lib/python3.7/site-packages/cloudvolume/datasource/precomputed/metadata.py in __init__(self, cloudpath, cache, info, provenance, max_redirects)
     50
     51     if info is None:
---> 52       self.refresh_info(max_redirects=max_redirects)
     53       if self.cache and self.cache.enabled:
     54         self.cache.check_info_validity()

~/python3.7/lib/python3.7/site-packages/cloudvolume/datasource/precomputed/metadata.py in refresh_info(self, max_redirects)
    170         return self.info
    171
--> 172     self.info = self.redirectable_fetch_info(max_redirects)
    173
    174     if self.cache:

~/python3.7/lib/python3.7/site-packages/cloudvolume/datasource/precomputed/metadata.py in redirectable_fetch_info(self, max_redirects)
    232
    233     for _ in range(max_redirects):
--> 234       info = self.fetch_info()
    235
    236       if 'redirect' not in info or not info['redirect']:

~/python3.7/lib/python3.7/site-packages/cloudvolume/datasource/precomputed/metadata.py in fetch_info(self)
    189     """
    190     with SimpleStorage(self.cloudpath) as stor:
--> 191       info = stor.get_json('info')
    192
    193     if info is None:

~/python3.7/lib/python3.7/site-packages/cloudvolume/storage/storage.py in get_json(self, file_path)
     60
     61   def get_json(self, file_path):
---> 62     content = self.get_file(file_path)
     63     if content is None:
     64       return None

~/python3.7/lib/python3.7/site-packages/cloudvolume/storage/storage.py in get_file(self, file_path, start, end)
    162     """
    163     content, encoding = self._interface.get_file(file_path, start=start, end=end)
--> 164     content = compression.decompress(content, encoding, filename=file_path)
    165     return content
    166

~/python3.7/lib/python3.7/site-packages/cloudvolume/compression.py in decompress(content, encoding, filename)
     38     raise
     39
---> 40   raise NotImplementedError(str(encoding) + ' is not currently supported. Supported Options: None, gzip')
     41
     42 def compress(content, method='gzip', compress_level=None):

NotImplementedError: utf-8 is not currently supported. Supported Options: None, gzip
[4]:
import glob, feather
feathers = glob.glob('*.feather')


for count, feather_file in enumerate(feathers):
    if count == 0:
        data = feather.read_dataframe(feather_file)
    else:
        df = feather.read_dataframe(feather_file)
        data = pd.concat([data, df])
data.shape
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-e4063d094774> in <module>
      9         df = feather.read_dataframe(feather_file)
     10         data = pd.concat([data, df])
---> 11 data.shape

NameError: name 'data' is not defined
[5]:
data.head()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-304fa4ce4ebd> in <module>
----> 1 data.head()

NameError: name 'data' is not defined
[6]:
from sklearn.preprocessing import StandardScaler
X = data.iloc[:, 3:]
X = StandardScaler().fit_transform(X)

y = data["Label"]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-e18551777f17> in <module>
      1 from sklearn.preprocessing import StandardScaler
----> 2 X = data.iloc[:, 3:]
      3 X = StandardScaler().fit_transform(X)
      4
      5 y = data["Label"]

NameError: name 'data' is not defined
[7]:
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=1)
clf = MLPClassifier(hidden_layer_sizes=4, activation="logistic", alpha=1, max_iter=1000).fit(X_train, y_train)
y_score = clf.predict_proba(X_test)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-4ef281fe3229> in <module>
      1 from sklearn.neural_network import MLPClassifier
      2 from sklearn.model_selection import train_test_split
----> 3 X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=1)
      4 clf = MLPClassifier(hidden_layer_sizes=4, activation="logistic", alpha=1, max_iter=1000).fit(X_train, y_train)
      5 y_score = clf.predict_proba(X_test)

NameError: name 'X' is not defined
[8]:
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
fpr, tpr, _ = roc_curve(y_test, y_score[:,1])
roc_auc = auc(fpr, tpr)

plt.figure()
lw = 2
plt.plot(fpr, tpr, color='darkorange',
         lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('MLP ROC')
plt.legend(loc="lower right")
plt.show()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-fdbfec346d7e> in <module>
      1 import matplotlib.pyplot as plt
      2 from sklearn.metrics import roc_curve, auc
----> 3 fpr, tpr, _ = roc_curve(y_test, y_score[:,1])
      4 roc_auc = auc(fpr, tpr)
      5

NameError: name 'y_test' is not defined
[9]:
from brainlit.feature_extraction.neighborhood import subsample
[10]:
X.shape
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-bc5f1a0adac8> in <module>
----> 1 X.shape

NameError: name 'X' is not defined
[11]:
from sklearn.linear_model import LogisticRegression
Xc_train, Xc_test, yc_train, yc_test = train_test_split(X, y, stratify=y, random_state=1)
clf = LogisticRegression(random_state=1, max_iter=2000).fit(Xc_train, yc_train)
yc_score = clf.predict_proba(Xc_test)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-4f6f80d20988> in <module>
      1 from sklearn.linear_model import LogisticRegression
----> 2 Xc_train, Xc_test, yc_train, yc_test = train_test_split(X, y, stratify=y, random_state=1)
      3 clf = LogisticRegression(random_state=1, max_iter=2000).fit(Xc_train, yc_train)
      4 yc_score = clf.predict_proba(Xc_test)

NameError: name 'X' is not defined
[12]:
fpr_c, tpr_c, _ = roc_curve(yc_test, yc_score[:,1])
roc_auc_c = auc(fpr_c, tpr_c)

plt.figure()
lw = 2
plt.plot(fpr_c, tpr_c, color='darkorange',
         lw=lw, label='ROC curve (area = %0.2f)' % roc_auc_c)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('LogRegression Receiver operating characteristic')
plt.legend(loc="lower right")
plt.show()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-37174ea46df2> in <module>
----> 1 fpr_c, tpr_c, _ = roc_curve(yc_test, yc_score[:,1])
      2 roc_auc_c = auc(fpr_c, tpr_c)
      3
      4 plt.figure()
      5 lw = 2

NameError: name 'yc_test' is not defined
[ ]: