Could you elaborate that a bit more
are you referring to the environment
I followed steps here after going thru alot of resources
https://github.com/mrdbourke/m1-machine-learning-test#how-to-setup-a-tensorflow-environment-on-m1-m1-pro-m1-max-using-miniforge-shorter-version
If i open jupyter notebok from here for now it seems to work
https://drive.google.com/file/d/1XNoAShO6y30TQ4hNpPvZqwDkHPWjDiW1/view?usp=sharing
but i m not sure how to switch to another environment
can you suggest something there
Post
Replies
Boosts
Views
Activity
Hi Team,
The steps share in https://developer.apple.com/metal/tensorflow-plugin/ are nicely explained but it returns error when trying to load via terminal
My course is getting affected big time as Google colab is not the right alternate and Jupyter has to work on my system
Some commands dont work on colab pls help me get this fixed
(base) keshavlalseth@Keshavs-MacBook-Air ~ % conda install -c apple tensorflow-deps
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- tensorflow-deps
Current channels:
- https://conda.anaconda.org/apple/osx-64
- https://conda.anaconda.org/apple/noarch
- https://repo.anaconda.com/pkgs/main/osx-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
(base) keshavlalseth@Keshavs-MacBook-Air ~ % python -m pip install tensorflow-macos
Collecting tensorflow-macos
ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none)
ERROR: No matching distribution found for tensorflow-macos
(base) keshavlalseth@Keshavs-MacBook-Air ~ % python -m pip install tensorflow-metal
Collecting tensorflow-metal
ERROR: Could not find a version that satisfies the requirement tensorflow-metal (from versions: none)
ERROR: No matching distribution found for tensorflow-metal
(base) keshavlalseth@Keshavs-MacBook-Air ~ % conda install -c apple tensorflow-deps==2.5.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- tensorflow-deps==2.5.0
Current channels:
- https://conda.anaconda.org/apple/osx-64
- https://conda.anaconda.org/apple/noarch
- https://repo.anaconda.com/pkgs/main/osx-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
These steps in apple's help article dont help at all
Ok any thoughts and comments on rest of the steps mentions that I have followed
Also, where and how below mentioned to use these and other commands conda terminal post opening jupyter notebook?
Download and install Conda env:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
Hi,
Thanks for your response!
--Which OS version and version of the MacBook Air (Intel or M1) are you running on?
MacBook Air - 13" (M1)
--Which versions of the Jupyter packages and Tensorflow packages are you using?
I've downloaded Anaconda from link available online https://www.anaconda.com/products/individual
It has Jupyter 6.4.5 in it.
It was working fine until Deep - ANN. The moment I started coding for CNN it returned error kernel died. I did not change anything. So it quite strange what happened. Hopeful of getting it fixed thrpugh this thread :-)
Same for Tensorflow as well https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/
--Did you follow the instructions at https://developer.apple.com/metal/tensorflow-plugin/ when installing?
No, sorry. I wasn't familiar with this resource. I m not able to follow this resource. could you explain & if this is necessary after having above steps doen and they been working fine earlier
--Can you provide an example script that causes the crash for you so we can try to reproduce this issue?
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
#import os
#os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
#os.environ["CUDA_VISIBLE_DEVICES"]="0"
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D,MaxPooling2D,Flatten,Dense
from tensorflow.keras.preprocessing import image
flower_classifier=Sequential()
flower_classifier.add(Conv2D(16,(3,3),input_shape=(128,128,3),activation='relu'))
flower_classifier.add(MaxPooling2D(pool_size=(2,2)))
flower_classifier.add(Conv2D(32,(3,3),activation='relu'))
flower_classifier.add(MaxPooling2D(pool_size=(2,2)))
flower_classifier.add(Flatten())
flower_classifier.add(Dense(units=128,activation='relu'))
flower_classifier.add(Dense(units=5,activation='softmax'))
flower_classifier.summary()
Model: "sequential"
Layer (type) Output Shape Param #
conv2d (Conv2D) (None, 126, 126, 16) 448
max_pooling2d (MaxPooling2D (None, 63, 63, 16) 0
)
conv2d_1 (Conv2D) (None, 61, 61, 32) 4640
max_pooling2d_1 (MaxPooling (None, 30, 30, 32) 0
2D)
flatten (Flatten) (None, 28800) 0
dense (Dense) (None, 128) 3686528
dense_1 (Dense) (None, 5) 645
=================================================================
Total params: 3,692,261
Trainable params: 3,692,261
Non-trainable params: 0
Make the data ready
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_datagen=ImageDataGenerator(rescale=1/255.,
rotation_range=45,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='reflect')
test_datagen=ImageDataGenerator(rescale=1/255.)
train_datagen
<keras.preprocessing.image.ImageDataGenerator at 0x1b013414c18>
train_set=train_datagen.flow_from_directory('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\Training',
target_size=(128,128),
batch_size=128,
class_mode='categorical')
test_set=test_datagen.flow_from_directory('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\Testing',
target_size=(128,128),
batch_size=128,
class_mode='categorical')
flower_classifier.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
flower_classifier.fit(train_set,
steps_per_epoch=2736//128,
epochs=5,
validation_data=test_set,
validation_steps=934//128)
type(test_img)
test_img1=image.img_to_array(test_img)
test_img1
test_img1=test_img1/255.
test_img1.shape
test_img2=np.expand_dims(test_img1,axis=0)
test_img2.shape
ypred=flower_classifier.predict(test_img2)
ypred.round(2)
print(train_set.class_indices)
Testing the model with single image
test_img=image.load_img('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\example\1.jpg',target_size=(128,128))
test_img1=image.img_to_array(test_img)
test_img1=test_img1/255.
test_img2=np.expand_dims(test_img1,axis=0)
ypred=flower_classifier.predict(test_img2)
print(train_set.class_indices)
print('The test image class is :',ypred.argmax())
class_name=train_set.class_indices
pos=np.array(list(class_name.values()))==ypred.argmax()
name=np.array(list(class_name.keys()))
print('The Predicted class name is:')
print(name[pos][0])
test_img
flower_classifier.save('flower_classifier.h5')
Please let me know if I can give you any other details