C
C#2y ago
πR

❔ Image classification AI / how to start learning AI in c#

Hey so I have a good knowledge in c# and now wanted to start learning how to develop Artificial intelligence As a first project I thought of an AI that can classify images. Where could I learn to develop such a thing from scratch? I already saw that Microsoft hat a tutorial on developing an AI using an already pretrained TensorFlow model, however I would really like to learn doing such things from scratch (so that I can learn how to develop other AIs for other use cases)
15 Replies
sibber
sibber2y ago
first step is to use python
x0rld 👻 🎃
there is ml.NET maybe ?
sibber
sibber2y ago
yes but i heard its shit and ive never seen anyone serious about machine learning use anything other than python
πR
πROP2y ago
Well but I hate python
x0rld 👻 🎃
there is some java too
sibber
sibber2y ago
dont when
πR
πROP2y ago
And there is TensorFlow in c# too TensoFlow.NET its called I think. But I heard that this could be quite difficult to start with as a first project would Java be better than c# for AI ?
x0rld 👻 🎃
idk there may be a bigger community as I see in the tensorflow.NET you can more or less follow python guide and translate it to c#
x0rld 👻 🎃
for basic things it's the same xD
πR
πROP2y ago
hmm sounds not thaaaat bad damn chatGPT lied to me... It said it wouldn't matter if I use python or c# cause both is possible... however it's quite difficult to understand how all of this works with no explanation nowhere in the internet
x0rld 👻 🎃
it's from tensorflow.NET readme chatGPT doesn't know the mean of catderp just reply with something "logic"
πR
πROP2y ago
yeah but maybe I could ask chatgpt to tell me how to implement such a model in c# I'll try this. wait a minute
**using System;
using System.IO;
using Tensorflow;
using Tensorflow.Image;
using Tensorflow.Keras;
using static Tensorflow.Binding;

class Program
{
static void Main(string[] args)
{
// Load the dataset
var (train_images, train_labels) = Cifar10.LoadTrainImages();

// Build the model
var model = keras.Sequential(
keras.layers.Conv2D(filters: 32, kernel_size: (3, 3), activation: tf.nn.relu, input_shape: (32, 32, 3)),
keras.layers.MaxPooling2D(pool_size: (2, 2)),
keras.layers.Flatten(),
keras.layers.Dense(units: 10, activation: tf.nn.softmax)
);

// Compile the model
model.compile(optimizer: keras.optimizers.Adam(), loss: keras.losses.SparseCategoricalCrossentropy(), metrics: new[] { "accuracy" });

// Train the model
model.fit(train_images, train_labels, epochs: 10, batch_size: 32);

// Evaluate the model
var (test_images, test_labels) = Cifar10.LoadTestImages();
var (loss, acc) = model.evaluate(test_images, test_labels);
Console.WriteLine($"Test loss: {loss}");
Console.WriteLine($"Test accuracy: {acc}");

// Use the model to classify new images
var imageBytes = File.ReadAllBytes("test_image.jpg");
var imageTensor = image.decode_jpeg(imageBytes);
var resizedImageTensor = image.resize_bilinear(imageTensor, new TensorShape(32, 32));
var expandedImageTensor = tf.expand_dims(resizedImageTensor, axis: 0);
var predictions = model.predict(expandedImageTensor);
Console.WriteLine(predictions.ToString());
}
}**
**using System;
using System.IO;
using Tensorflow;
using Tensorflow.Image;
using Tensorflow.Keras;
using static Tensorflow.Binding;

class Program
{
static void Main(string[] args)
{
// Load the dataset
var (train_images, train_labels) = Cifar10.LoadTrainImages();

// Build the model
var model = keras.Sequential(
keras.layers.Conv2D(filters: 32, kernel_size: (3, 3), activation: tf.nn.relu, input_shape: (32, 32, 3)),
keras.layers.MaxPooling2D(pool_size: (2, 2)),
keras.layers.Flatten(),
keras.layers.Dense(units: 10, activation: tf.nn.softmax)
);

// Compile the model
model.compile(optimizer: keras.optimizers.Adam(), loss: keras.losses.SparseCategoricalCrossentropy(), metrics: new[] { "accuracy" });

// Train the model
model.fit(train_images, train_labels, epochs: 10, batch_size: 32);

// Evaluate the model
var (test_images, test_labels) = Cifar10.LoadTestImages();
var (loss, acc) = model.evaluate(test_images, test_labels);
Console.WriteLine($"Test loss: {loss}");
Console.WriteLine($"Test accuracy: {acc}");

// Use the model to classify new images
var imageBytes = File.ReadAllBytes("test_image.jpg");
var imageTensor = image.decode_jpeg(imageBytes);
var resizedImageTensor = image.resize_bilinear(imageTensor, new TensorShape(32, 32));
var expandedImageTensor = tf.expand_dims(resizedImageTensor, axis: 0);
var predictions = model.predict(expandedImageTensor);
Console.WriteLine(predictions.ToString());
}
}**
To implement an AI model in C# with TensorFlow.NET to classify images, you can follow these general steps:

Prepare the dataset: You need to have a set of images that are labeled according to their corresponding classes. You can create your own dataset or use an existing one.

Build the model architecture: Define the layers, activation functions, and loss function of the model. You can use pre-trained models like VGG, ResNet, or Inception, or you can build your own model architecture.

Compile the model: Compile the model with an optimizer and metrics for evaluation.

Train the model: Train the model with the prepared dataset, adjust the model's parameters, and monitor its performance.

Evaluate the model: Evaluate the model on a test set to see how well it performs on unseen data.

Use the model: Once you have a trained model, you can use it to classify new images.

Here is an example code snippet to get you started:
To implement an AI model in C# with TensorFlow.NET to classify images, you can follow these general steps:

Prepare the dataset: You need to have a set of images that are labeled according to their corresponding classes. You can create your own dataset or use an existing one.

Build the model architecture: Define the layers, activation functions, and loss function of the model. You can use pre-trained models like VGG, ResNet, or Inception, or you can build your own model architecture.

Compile the model: Compile the model with an optimizer and metrics for evaluation.

Train the model: Train the model with the prepared dataset, adjust the model's parameters, and monitor its performance.

Evaluate the model: Evaluate the model on a test set to see how well it performs on unseen data.

Use the model: Once you have a trained model, you can use it to classify new images.

Here is an example code snippet to get you started:
This doesn't even make sense?!
sibber
sibber2y ago
$chatgpt
MODiX
MODiX2y ago
ChatGPT is a text prediction algorithm. This means that it takes your input and responds with what it thinks sounds reasonable. However, it can't perform any judgement of the factuality of its responses. For this reason, it should not be relied upon for concrete advice or facts.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server