Post

Replies

Boosts

Views

Activity

Swift Data Predicate failing for String Array
In Swift Data I have a basic model @Model class MovieSD { @Attribute(.unique) var title: String var genre: [String] = [String]() init(title: String) { self.title = title } } I am trying to create predicates when fetching the data. Creating a predicate to search by title works as expected let movieTitle = #Predicate<MovieSD> { movie in movie.title.contains("filterstring") } But when attempting to do the same for the String array let movieGenre = #Predicate<MovieSD> { movie in movie.genre.contains("filterstring") } Results in a crash with EXC_BAD_ACCESS Similar approaches produce a different error and point to the likely issue. let movieGenre2 = #Predicate<MovieSD> { movie in if movie.genre.contains(where: { $0 == "filterstring" }) { return true } else { return false } } Results in a crash with the error: error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x281a96840> , Can't have a non-relationship collection element in a subquerySUBQUERY(genre, $$_local_1, $$_local_1 == "SciFi") with userInfo of (null) or alternatively largely the same error for: let movieGenre3 = #Predicate<MovieSD> { movie in movie.genre.filter { genre in return genre == "filterstring" }.count > 0 } But I couldn't seem to find an approach to create a SUBQUERY with #Predicate Naturally, I can use similar to the above to filter the array that is returned. But this seems inefficient. And it seems it should be possible to filter Any help showing how to filter a String array with a predicate with Swift Data would be appreciated
0
0
262
Sep ’24
How to use GCVirtualController directly with SKScene?
GCVirtualController isn't displaying when used with SKScene class. The Virtual controllers appear but then it seems that they are obscured by the SKScene itself!? The documentation says that calling connect() will display the virtual controllers but I seem to be missing how to add the controllers to the SKScene? class GameScene: SKScene { private var _virtualController: Any? @available(iOS 15.0, *) public var virtualController: GCVirtualController? { get { return self._virtualController as? GCVirtualController } set { self._virtualController = newValue } } override func didMove(to view: SKView) { let background = SKSpriteNode(imageNamed: ".jpg") background.zPosition = -1 addChild(background) let virtualConfig = GCVirtualController.Configuration() virtualConfig.elements = [GCInputLeftThumbstick, GCInputRightThumbstick, GCInputButtonA, GCInputButtonB] virtualController = GCVirtualController(configuration: virtualConfig) virtualController?.connect() } } I've also tried adding the virtual controllers in the UIViewController but this doesn't work either.
5
0
1.9k
Oct ’21
zsh: illegal hardware instruction on following tensorflow-metal tutorial
On an Apple M1 with Ventura 13.6. I followed the steps on the Get started with tensorflow-metal page here: https://developer.apple.com/metal/tensorflow-plugin/ python3 -m venv ~/venv-metal source ~/venv-metal/bin/activate python -m pip install -U pip python -m pip install tensorflow python -m pip install tensorflow-metal With a clean start I also tried a pinning python -m pip install tensorflow==2.13.0 Where Successfully installed tensorflow-metal-1.0.0 The table here suggested this should work. https://pypi.org/project/tensorflow-metal/ But I got the same error... Running Python code without the tensorflow import was not a problem. I found forums with similar error on Mac 1 but none of the proposed solution worked. Is there suggested steps to get the `get started tutorial working?
0
0
1.7k
Feb ’24
CoreML Conversion of TensorFlow Keras NN fails on Iris Data set
On tf version 2.11.0. I have tried to follow on a fairly standard NN example in order to convert to a CoreML model. However, I cannot get this to work and I'm not clear where it is going wrong. It would seem to be a fairly standard task - a toy example - and I can't see why the conversion would fail. Any help would be appreciated. I have tried the different approaches listed below, but it seems the conversion should just work. I have also tried running the same code pinned to: tensorflow==2.6.2 scikit-learn==0.19.2 pandas==1.1.1 And get a different sequence of errors. The Python code I used mostly comes form this example: https://lnwatson.co.uk/posts/intro_to_nn/ import pandas as pd import numpy as np import tensorflow as tf import torch from sklearn.model_selection import train_test_split from tensorflow import keras import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' np.bool = np.bool_ np.int = np.int_ print("tf version", tf.__version__) csv_url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' col_names = ['Sepal_Length','Sepal_Width','Petal_Length','Petal_Width','Class'] df = pd.read_csv(csv_url, names = col_names) labels = df.pop('Class') labels = pd.get_dummies(labels) X = df.values y = labels.values X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.05) X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2) model = keras.Sequential() model.add(keras.layers.Dense(16, activation='relu', input_shape=(4,))) model.add(keras.layers.Dense(3, activation='softmax')) model.summary() model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) model.fit(X_train, y_train, batch_size=12, epochs=200, validation_data=(X_val, y_val)) import coremltools as ct # Pass in `tf.keras.Model` to the Unified Conversion API mlmodel = ct.convert(model, convert_to="mlprogram") # mlmodel = ct.convert(model, source="tensorflow") # mlmodel = ct.convert(model, convert_to="neuralnetwork") # mlmodel = ct.convert( # model, # source="tensorflow", # inputs=[ct.TensorType(name="input")], # outputs=[ct.TensorType(name="output")], # minimum_deployment_target=ct.target.iOS14, # ) When using either of these 3: mlmodel = ct.convert(model, convert_to="mlprogram") mlmodel = ct.convert(model, source="tensorflow") mlmodel = ct.convert(model, convert_to="neuralnetwork") I get: mlmodel2 = ct.convert(model, source="tensorflow") ValueError: Const node 'sequential_5/dense_10/MatMul/ReadVariableOp' cannot have no value ERROR:root:sequential_5/dense_11/BiasAdd/ReadVariableOp:0 ERROR:root:[ 0.34652767 0.16202268 -0.3554725 ] Running TensorFlow Graph Passes: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 28.76 passes/s] Converting Frontend ==> MIL Ops: 8%|█████████████████ | 1/12 [00:00<00:00, 16710.37 ops/s] --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~/Documents/CoreML Basic Models/NN_Keras_Iris.py:142 130 import coremltools as ct 131 # Pass in `tf.keras.Model` to the Unified Conversion API 132 # mlmodel = ct.convert(model, convert_to="mlprogram") 133 (...) 140 141 # ct.convert(mymodel(), source="tensorflow") --> 142 mlmodel2 = ct.convert(model, source="tensorflow") 144 mlmodel = ct.convert( 145 model, 146 source="tensorflow", (...) 153 minimum_deployment_target=ct.target.iOS14, 154 ) .... File ~/opt/anaconda3/envs/coreml_env/lib/python3.8/site-packages/coremltools/converters/mil/frontend/tensorflow/ops.py:430, in Const(context, node) 427 @register_tf_op 428 def Const(context, node): 429 if node.value is None: --> 430 raise ValueError("Const node '{}' cannot have no value".format(node.name)) 431 mode = get_const_mode(node.value.val) 432 x = mb.const(val=node.value.val, mode=mode, name=node.name) ValueError: Const node 'sequential_5/dense_10/MatMul/ReadVariableOp' cannot have no value Second Approach: A different approach I tried was specifying the inout type TensorType. However, when specifying the input and outputs I get a different error. I have tried variations on this initialiser but all produce the same error. The variations revolve around adding input_shape, dtype=np.float32 mlmodel = ct.convert( model, source="tensorflow", inputs=[ct.TensorType(name="input")], outputs=[ct.TensorType(name="output")], minimum_deployment_target=ct.target.iOS14, ) t File ~/opt/anaconda3/envs/coreml_env/lib/python3.8/site-packages/coremltools/converters/mil/frontend/tensorflow/load.py:106, in <listcomp>(.0) 104 logging.debug(msg.format(outputs)) 105 outputs = outputs if isinstance(outputs, list) else [outputs] --> 106 outputs = [i.split(":")[0] for i in outputs] 107 if _get_version(tf.__version__) < _StrictVersion("1.13.1"): 108 return tf.graph_util.extract_sub_graph(graph_def, outputs) AttributeError: 'TensorType' object has no attribute 'split'
0
0
760
Jan ’24
Swift Package Manager and Xcode SSH authentication not working
On Xcode 15 running on Sonoma 14.2.1 attempting to add a package through SPM for a private repo hosted on Bitbucket is failing. (The issue has been experienced o Xcode 14 as well). On attempting to authenticate a new client Xcode is directing to login through Account and Password ignoring the SSH key. This issue is only affecting new clients. For existing clients this method of authentication continues to work. I'm following the steps here: https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-macos/ Specifically: Create an SSH key pair ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name} Or sh-keygen -t rsa -b 2048 -C "{username@emaildomain.com}" -f {ssh-key-name} Add your key to the SSH agent ssh-add ~/{ssh-key-name} Update and check correct SSH configuration. ~/.ssh/config Such as: Host bitbucket.org AddKeysToAgent yes IdentityFile ~/.ssh/{ssh-key-name} The key is then added as an Access Key to the repository on Bitbucket. Check that your SSH authentication works ssh -T git@bitbucket.org In then get the reponse: authenticated via ssh key. You can use git to connect to Bitbucket. Shell access is disabled Which Indicates that SSH can successfully connect with Bitbucket using the SSH key. I'm also able to Git clone, push, pull through terminal. But in Xcode, after adding a package dependency through "Add Package Dependency and enter its repository URL" The following dialog appears. On clicking Trust Xcode then will continue to ask for login through Account and Password. I have tried Quit Xcode if it's still running If still needed, fix your ssh problem (e.g. add your public key to the remote user's .ssh/authorized_keys). Test git in a shell (not in Xcode). E.g. "cd /tmp ; git clone ssh://.../path/repo.git" (in Terminal...) $ defaults delete com.apple.dt.xcode IDESourceControlKnownSSHHostsDefaultsKey $ sudo killall ssh-agent start Xcode and attempt to clone a project into a temporary directory using your ssh://... URL Open the original project which was causing grief in Xcode, and could successfully pull, fetch, whatever. But this did not resolve the issue
1
0
1.6k
Jan ’24
Bonjour Service Discovery using SwiftNIO
I’m working on cross platform IoT project that requires data between devices on the same WiFi network. Initially, SwiftNIO looked ideal but there appears to be no obvious way to broadcast and listen for a Bonjour service using SwiftNIO. Have I missed any obvious solution or can anyone give any pointers as to a good approach to take? The platforms I’m using are Linux, iOS, and MacOS. Apple's Network framework isn't supported on Linux so I ruled this out. Ideally, an approach using Swift but happy to consider other approaches.
1
0
1.3k
Jan ’22