OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

  • Thread starter Thread starter Encipher
  • Start date Start date
E

Encipher

Guest
I want to call my Python module from the Matlab. I received the error:

Code:
Error using numpy_ops>init thinc.backends.numpy_ops

Python Error:

Code:
 ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject.

The Python script is as follows

Code:
import spacy
def text_recognizer(model_path, text):
try:
    # Load the trained model
    nlp = spacy.load(model_path)
    print("Model loaded successfully.")
    
    # Process the given text
    doc = nlp(text)
    ent_labels = [(ent.text, ent.label_) for ent in doc.ents]
        return ent_labels

The Matlab script is as follows

Code:
% Set up the Python environment
        pe = pyenv;
        py.importlib.import_module('final_output');
        
        % Add the directory containing the Python script to the Python path
        path_add = fileparts(which('final_output.py'));
        if count(py.sys.path, path_add) == 0
            insert(py.sys.path, int64(0), path_add);
        end
        % Define model path and text to process
        model_path = 'D:\trained_model\\output\\model-best';
        text = 'Roses are red';
        % Call the Python function
        pyOut = py.final_output.text_recognizer(model_path, text);
        % Convert the output to a MATLAB cell array
        entity_labels = cell(pyOut);
        disp(entity_labels);

I found one solution to update Numpy, what I did, but nothing changed. I am using Python 3.9 and Numpy version 2.0.0

The error was received when I tried to call the Python module using a Matlab script.

How can I fix the issue?
<p>I want to call my Python module from the Matlab. I received the error:</p>
<pre><code>Error using numpy_ops>init thinc.backends.numpy_ops
</code></pre>
<p>Python Error:</p>
<pre><code> ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject.
</code></pre>
<p>The Python script is as follows</p>
<pre><code>import spacy
def text_recognizer(model_path, text):
try:
# Load the trained model
nlp = spacy.load(model_path)
print("Model loaded successfully.")

# Process the given text
doc = nlp(text)
ent_labels = [(ent.text, ent.label_) for ent in doc.ents]
return ent_labels
</code></pre>
<p>The Matlab script is as follows</p>
<pre><code>% Set up the Python environment
pe = pyenv;
py.importlib.import_module('final_output');

% Add the directory containing the Python script to the Python path
path_add = fileparts(which('final_output.py'));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = 'D:\trained_model\\output\\model-best';
text = 'Roses are red';
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels);
</code></pre>
<p>I found one solution to update Numpy, what I did, but nothing changed. I am using Python 3.9 and Numpy version 2.0.0</p>
<p>The error was received when I tried to call the Python module using a Matlab script.</p>
<p>How can I fix the issue?</p>
 

Latest posts

Top