Skip to content

Commit 3fb6404

Browse files
Merge pull request #63 from diffgram/depend
Move requirements to be optional
2 parents cde9ada + 9ca0983 commit 3fb6404

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

sdk/diffgram/brain/brain.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,7 @@
22

33
import tempfile
44

5-
try:
6-
import cv2
7-
except:
8-
print("Warning: Could not import cv2. Some SDK functions may not be available.")
9-
10-
try:
11-
import tensorflow as tf
12-
except:
13-
print("Warning: Could not import tensorflow. Some SDK functions may not be available")
14-
15-
import numpy as np
165
import requests
17-
import scipy.misc
18-
19-
import diffgram.utils.visualization_utils as vis_util
206

217

228
class Brain():
@@ -37,6 +23,20 @@ def __init__(
3723
if local is true will perform additional setup work local_setup()
3824
3925
"""
26+
try:
27+
import cv2
28+
except:
29+
print("Info: Could not import cv2. Some SDK functions may not be available.")
30+
31+
try:
32+
import tensorflow as tf
33+
except:
34+
print("Info: Could not import tensorflow. Some SDK functions may not be available")
35+
36+
import numpy as np
37+
import scipy.misc
38+
import diffgram.utils.visualization_utils as vis_util
39+
4040

4141
self.client = client
4242

sdk/diffgram/core/diffgram_dataset_iterator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import logging
22

3-
from PIL import Image, ImageDraw
4-
from imageio import imread
5-
import numpy as np
63
import traceback
74
import sys
85
from threading import Thread
@@ -137,6 +134,7 @@ def set_custom_url_signer(self, signer_fn: Callable):
137134
self.custom_signer_fn = signer_fn
138135

139136
def get_image_data(self, diffgram_file):
137+
from imageio import imread
140138
MAX_RETRIES = 10
141139
image = None
142140
if hasattr(diffgram_file, 'image'):
@@ -254,6 +252,8 @@ def get_file_instances(self, diffgram_file) -> dict:
254252
return sample
255253

256254
def extract_masks_from_polygon(self, instance_list, diffgram_file, empty_value = 0):
255+
from PIL import Image, ImageDraw
256+
import numpy as np
257257
nx, ny = diffgram_file.image['width'], diffgram_file.image['height']
258258
mask_list = []
259259
if nx is None or ny is None:

sdk/requirements.txt

-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
requests>=2.20.1
2-
opencv-python>=4.0.0.21
3-
scipy>=1.1.0
4-
six>=1.9.0
5-
tensorflow>=1.12.0
6-
pillow
7-
torch
8-
imageio>=2.9.0

sdk/setup.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
"Operating System :: OS Independent",
2525
],
2626
install_requires=[
27-
'requests>=2.20.1',
28-
'scipy>=1.1.0',
29-
'six>=1.9.0',
30-
'pillow>=6.1.0',
31-
'imageio>=2.9.0'
32-
]
27+
'requests>=2.20.1'
28+
],
29+
extras_require = {
30+
'ml': ["opencv-python>=4.0.0.21",
31+
'pillow>=6.1.0',
32+
'scipy>=1.1.0',
33+
'pillow>=6.1.0',
34+
'imageio>=2.9.0',
35+
'tensorflow>=1.12.0',
36+
'torch'
37+
]
38+
}
3339
)

0 commit comments

Comments
 (0)