title: TypeError: 'str' object is not callable | FastAi
body: <p>Goal: instantiate <code>unet_learner()</code> using <code>weights</code>.</p>
  <p><code>weights</code> is a <code>str</code> that I bring in from a user-defined <code>.yaml</code> file; hence <a href="https://www.programiz.com/python-programming/methods/built-in/eval" rel="nofollow noreferrer">eval()</a>.</p>
  <p><code>file_path</code> and <code>training</code> are classes that hold parameters.</p>
  <p>Code:</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  from fastai.vision.all import *
  
  
  def train(dls, file_path, training):
      labels = np.loadtxt(file_path.labels, dtype=str)
      weights = torch.tensor(eval(training.weights))
  
      print('#################')
      print(weights)
      print(type(weights))
      print('#################')
  
      learner = unet_learner(dls, training.architecture,loss_func=CrossEntropyLossFlat(
          axis=1,
          weight=weights)
      )
  
      return learner.load(file_path.weights)
  </code></pre>
  <p>Placing <code>torch.tensor()</code> around <code>weights</code> again in the parameter line doesn't help. Same error.</p>
  <p>Traceback:</p>
  <pre><code>(venv) me@ubuntu-pcs:~/PycharmProjects/project$ python pdl1_lung_train/main.py 
  /home/me/miniconda3/envs/venv/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  /opt/conda/conda-bld/pytorch_1607370156314/work/c10/cuda/CUDAFunctions.cpp:100.)
    return torch._C._cuda_getDeviceCount() &gt; 0
  #################
  tensor([0.4000, 0.9000])
  &lt;class 'torch.Tensor'&gt;
  #################
  Traceback (most recent call last):
    File &quot;pdl1_lung_train/main.py&quot;, line 27, in &lt;module&gt;
      main(ROOT)
    File &quot;pdl1_lung_train/main.py&quot;, line 19, in main
      learner = train(dls, file_path, training)
    File &quot;/home/me/PycharmProjects/project/pdl1_lung_train/train.py&quot;, line 16, in train
      weight=weights))
    File &quot;/home/me/miniconda3/envs/venv/lib/python3.7/site-packages/fastai/vision/learner.py&quot;, line 267, in unet_learner
      model = create_unet_model(arch, n_out, img_size, pretrained=pretrained, **kwargs)
    File &quot;/home/me/miniconda3/envs/venv/lib/python3.7/site-packages/fastai/vision/learner.py&quot;, line 243, in create_unet_model
      model = arch(pretrained)
  TypeError: 'str' object is not callable
  </code></pre>
  <p>Please let me know if I need to add other info. to post.</p>