Repository: towhee-io/towhee

Issue #935: import guard for missing modules
Created: 2022-03-29T05:29:48Z
import towhee
from towhee.functional import DataCollection
dataset = DataCollection.from_zip('https://towhee.io/towhee/image-dataset/media/branch/main/image_dataset.zip', '/dataset/.JPEG').unstream()
query = DataCollection.from_zip('https://towhee.io/towhee/image-dataset/media/branch/main/image_dataset.zip', '/query/.JPEG').unstream()
dc_data = dataset.image_load().towhee.resnet_image_embedding(model_name='resnet50').select('feature_vector')
Traceback (most recent call last):
File "", line 1, in 
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/hparam/hyperparameter.py", line 205, in call
return self._callback(self._path, self._index, *args, **kwds)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 652, in wrapper
return self.map(op)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 26, in wrapper
return self.factory(func(self, *arg, **kws))
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 216, in wrapper
return creator(*arg, **kws)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 171, in unstream
iterable = list(iterable)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 389, in inner
return unary_op(x)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/engine/factory.py", line 93, in call
res = self._op(*arg, **kws)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/engine/operator_registry.py", line 199, in wrapper_call
return old_call(self, *args, **kws)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/engine/operator_registry.py", line 183, in call
return old_cls(*arg, **kws)
File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/hub/builtin/operators/computer_vision.py", line 44, in image_load
import cv2
ModuleNotFoundError: No module named 'cv2'




I believe that we moved away from cv2 being a requiremnet. We might need to add checks with messages to prompt cv2 install. I saw that a few of our mixins still use it @reiase
Originally posted by @filip-halt in #891 (comment)

Duplicate issue #971: [Bug]: Try towhee's example with the error "No module named 'sklearn'"
Created: 2022-03-31T07:24:31Z
Is there an existing issue for this?

 I have searched the existing issues

Current Behavior
>>> from towhee.functional import DataCollection
>>> dc = DataCollection.range(10)
>>> train, test = dc.split_train_test(shuffle=False)
2022-03-31 15:23:03,907 - 4600618496 - sklearn_utils.py-sklearn_utils:21 - ERROR: sklearn not found, you can install via `pip install scikit-learn`.
Traceback (most recent call last):
  File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/utils/sklearn_utils.py", line 18, in <module>
    from sklearn.metrics import confusion_matrix, accuracy_score, recall_score
ModuleNotFoundError: No module named 'sklearn'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/functional/mixins/dataset.py", line 162, in split_train_test
    from towhee.utils import sklearn_utils
  File "/Users/jingjing/miniconda3/envs/tw/lib/python3.9/site-packages/towhee/utils/sklearn_utils.py", line 22, in <module>
    raise ModuleNotFoundError('sklearn not found, you can install via `pip install scikit-learn`.') from e
ModuleNotFoundError: sklearn not found, you can install via `pip install scikit-learn`.

Expected Behavior
No response
Steps To Reproduce
No response
Environment
- Towhee version(e.g. v0.1.3 or 8b23a93):towhee==0.5.1.dev103
- OS(Ubuntu or CentOS):macos
- CPU/Memory:
- GPU:
- Others:
Anything else?
No response

Closing comment (2022-04-01T03:12:40Z): /duplicate #935

The document is not completely revised, right?

You are right, we will add the requirements before using DataColleation in docs.